Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/MHTextIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct {
@property NSSortOptions sortOptions;
@property NSUInteger minimalTokenLength;
@property BOOL skipStopWords;
@property BOOL indexAllSubstrings;
@property BOOL discardDuplicateTokens;

@property (strong, readonly) NSString * path;
Expand Down
12 changes: 9 additions & 3 deletions Classes/MHTextIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void removeIndexForStringInObject(NSData *ident, NSUInteger stringIdx, LDBWriteb
}];
}
void indexWordInObjectTextFragment(NSData *ident, NSStringEncoding encoding, bloom_filter_s *bloomFilter,
NSUInteger minimalTokenLength, BOOL skipStopWords,
NSUInteger minimalTokenLength, BOOL skipStopWords, BOOL indexAllSubstrings,
NSString *wordSubstring, NSRange wordSubstringRange, NSUInteger stringIdx,
LDBWritebatch *wb) {

Expand Down Expand Up @@ -265,6 +265,9 @@ void indexWordInObjectTextFragment(NSData *ident, NSStringEncoding encoding, blo

// ... and append the key bytes, without the leading type 0
[keys appendBytes:key length:(NSUInteger)keyLength];

// run only the first loop that indexes the whole word if not indexing all substrings
if (!indexAllSubstrings) break;
}

// Finally, for each indexed word, we need to insert a reversed index entry for bookkeeping
Expand Down Expand Up @@ -314,6 +317,7 @@ - (instancetype)initWithName:(NSString *)name path:(NSString *)path options:(Lev
_indexingQueue.maxConcurrentOperationCount = 10;

_minimalTokenLength = 2;
_indexAllSubstrings = YES;
_skipStopWords = YES;
_discardDuplicateTokens = NO;

Expand Down Expand Up @@ -443,7 +447,8 @@ - (NSOperation *)indexObject:(id)object {
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
indexWordInObjectTextFragment(ident, encoding, bloomFilter,
_sself->_minimalTokenLength, _sself->_skipStopWords,
substring, substringRange, idx, wb);
_sself->_indexAllSubstrings, substring,
substringRange, idx, wb);
}];

if (_sself->_discardDuplicateTokens)
Expand Down Expand Up @@ -519,7 +524,8 @@ - (NSOperation *)updateIndexForObject:(id)object {
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
indexWordInObjectTextFragment(ident, encoding, bloomFilter,
_sself->_minimalTokenLength, _sself->_skipStopWords,
substring, substringRange, idx, wb);
_sself->_indexAllSubstrings, substring,
substringRange, idx, wb);
}];

if (_sself->_discardDuplicateTokens)
Expand Down