Lines 132-142
Link Here
|
132 |
} |
132 |
} |
133 |
return results; |
133 |
return results; |
134 |
} |
134 |
} |
135 |
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable wordsToDocNumbers, MemoryIndex memoryIndex) throws IOException { |
135 |
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable wordsToDocNumbers, MemoryIndex memoryIndex, boolean checkBeforeAdd) throws IOException { |
136 |
// must skip over documents which have been added/changed/deleted in the memory index |
136 |
// must skip over documents which have been added/changed/deleted in the memory index |
137 |
if (results == null) |
137 |
if (results == null) |
138 |
results = new HashtableOfObject(13); |
138 |
results = new HashtableOfObject(13); |
139 |
EntryResult result = (EntryResult) results.get(word); |
139 |
EntryResult result = null; |
|
|
140 |
if (checkBeforeAdd) |
141 |
result = (EntryResult) results.get(word); |
140 |
if (memoryIndex == null) { |
142 |
if (memoryIndex == null) { |
141 |
if (result == null) |
143 |
if (result == null) |
142 |
results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); |
144 |
results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); |
Lines 161-166
Link Here
|
161 |
if (this.categoryOffsets == null) return null; // file is empty |
163 |
if (this.categoryOffsets == null) return null; // file is empty |
162 |
|
164 |
|
163 |
HashtableOfObject results = null; // initialized if needed |
165 |
HashtableOfObject results = null; // initialized if needed |
|
|
166 |
boolean checkBeforeAdd = memoryIndex != null; // used to optimize adding the results |
164 |
if (key == null) { |
167 |
if (key == null) { |
165 |
for (int i = 0, l = categories.length; i < l; i++) { |
168 |
for (int i = 0, l = categories.length; i < l; i++) { |
166 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
169 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
Lines 170-176
Link Here
|
170 |
results = new HashtableOfObject(wordsToDocNumbers.elementSize); |
173 |
results = new HashtableOfObject(wordsToDocNumbers.elementSize); |
171 |
for (int j = 0, m = words.length; j < m; j++) |
174 |
for (int j = 0, m = words.length; j < m; j++) |
172 |
if (words[j] != null) |
175 |
if (words[j] != null) |
173 |
results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex); |
176 |
results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
|
|
177 |
checkBeforeAdd = true; |
174 |
} |
178 |
} |
175 |
} |
179 |
} |
176 |
if (results != null && this.cachedChunks == null) |
180 |
if (results != null && this.cachedChunks == null) |
Lines 180-187
Link Here
|
180 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
184 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
181 |
for (int i = 0, l = categories.length; i < l; i++) { |
185 |
for (int i = 0, l = categories.length; i < l; i++) { |
182 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
186 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
183 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) |
187 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) { |
184 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex); |
188 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
|
|
189 |
checkBeforeAdd = true; |
190 |
} |
185 |
} |
191 |
} |
186 |
break; |
192 |
break; |
187 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
193 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
Lines 192-199
Link Here
|
192 |
for (int j = 0, m = words.length; j < m; j++) { |
198 |
for (int j = 0, m = words.length; j < m; j++) { |
193 |
char[] word = words[j]; |
199 |
char[] word = words[j]; |
194 |
if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) |
200 |
if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) |
195 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex); |
201 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
196 |
} |
202 |
} |
|
|
203 |
checkBeforeAdd = true; |
197 |
} |
204 |
} |
198 |
} |
205 |
} |
199 |
break; |
206 |
break; |
Lines 205-212
Link Here
|
205 |
for (int j = 0, m = words.length; j < m; j++) { |
212 |
for (int j = 0, m = words.length; j < m; j++) { |
206 |
char[] word = words[j]; |
213 |
char[] word = words[j]; |
207 |
if (word != null && Index.isMatch(key, word, matchRule)) |
214 |
if (word != null && Index.isMatch(key, word, matchRule)) |
208 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex); |
215 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
209 |
} |
216 |
} |
|
|
217 |
checkBeforeAdd = true; |
210 |
} |
218 |
} |
211 |
} |
219 |
} |
212 |
} |
220 |
} |