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 = checkBeforeAdd ? (EntryResult) results.get(word) : null; |
140 |
if (memoryIndex == null) { |
140 |
if (memoryIndex == null) { |
141 |
if (result == null) |
141 |
if (result == null) |
142 |
results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); |
142 |
results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); |
Lines 161-166
Link Here
|
161 |
if (this.categoryOffsets == null) return null; // file is empty |
161 |
if (this.categoryOffsets == null) return null; // file is empty |
162 |
|
162 |
|
163 |
HashtableOfObject results = null; // initialized if needed |
163 |
HashtableOfObject results = null; // initialized if needed |
|
|
164 |
|
165 |
// No need to check the results table for duplicacy while processing the |
166 |
// first category table or if the first category tables doesn't have any results. |
167 |
boolean checkBeforeAdd = false; |
164 |
if (key == null) { |
168 |
if (key == null) { |
165 |
for (int i = 0, l = categories.length; i < l; i++) { |
169 |
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 |
170 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
Lines 168-176
Link Here
|
168 |
char[][] words = wordsToDocNumbers.keyTable; |
172 |
char[][] words = wordsToDocNumbers.keyTable; |
169 |
if (results == null) |
173 |
if (results == null) |
170 |
results = new HashtableOfObject(wordsToDocNumbers.elementSize); |
174 |
results = new HashtableOfObject(wordsToDocNumbers.elementSize); |
171 |
for (int j = 0, m = words.length; j < m; j++) |
175 |
for (int j = 0, m = words.length; j < m; j++) { |
172 |
if (words[j] != null) |
176 |
if (words[j] != null) |
173 |
results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex); |
177 |
results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
|
|
178 |
} |
179 |
checkBeforeAdd = true; |
174 |
} |
180 |
} |
175 |
} |
181 |
} |
176 |
if (results != null && this.cachedChunks == null) |
182 |
if (results != null && this.cachedChunks == null) |
Lines 180-187
Link Here
|
180 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
186 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
181 |
for (int i = 0, l = categories.length; i < l; i++) { |
187 |
for (int i = 0, l = categories.length; i < l; i++) { |
182 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
188 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
183 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) |
189 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) { |
184 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex); |
190 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
|
|
191 |
checkBeforeAdd = true; |
192 |
} |
185 |
} |
193 |
} |
186 |
break; |
194 |
break; |
187 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
195 |
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++) { |
200 |
for (int j = 0, m = words.length; j < m; j++) { |
193 |
char[] word = words[j]; |
201 |
char[] word = words[j]; |
194 |
if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) |
202 |
if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) |
195 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex); |
203 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
196 |
} |
204 |
} |
|
|
205 |
checkBeforeAdd = true; |
197 |
} |
206 |
} |
198 |
} |
207 |
} |
199 |
break; |
208 |
break; |
Lines 205-212
Link Here
|
205 |
for (int j = 0, m = words.length; j < m; j++) { |
214 |
for (int j = 0, m = words.length; j < m; j++) { |
206 |
char[] word = words[j]; |
215 |
char[] word = words[j]; |
207 |
if (word != null && Index.isMatch(key, word, matchRule)) |
216 |
if (word != null && Index.isMatch(key, word, matchRule)) |
208 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex); |
217 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, checkBeforeAdd); |
209 |
} |
218 |
} |
|
|
219 |
checkBeforeAdd = true; |
210 |
} |
220 |
} |
211 |
} |
221 |
} |
212 |
} |
222 |
} |