Lines 132-151
Link Here
|
132 |
} |
132 |
} |
133 |
return results; |
133 |
return results; |
134 |
} |
134 |
} |
135 |
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable wordsToDocNumbers, MemoryIndex memoryIndex, boolean prevResults) throws IOException { |
135 |
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, Object docs, MemoryIndex memoryIndex, boolean prevResults) 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 = prevResults ? (EntryResult) results.get(word) : null; |
139 |
EntryResult result = prevResults ? (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, docs)); |
143 |
else |
143 |
else |
144 |
result.addDocumentTable(wordsToDocNumbers); |
144 |
result.addDocumentTable(docs); |
145 |
} else { |
145 |
} else { |
146 |
SimpleLookupTable docsToRefs = memoryIndex.docsToReferences; |
146 |
SimpleLookupTable docsToRefs = memoryIndex.docsToReferences; |
147 |
if (result == null) result = new EntryResult(word, null); |
147 |
if (result == null) result = new EntryResult(word, null); |
148 |
int[] docNumbers = readDocumentNumbers(wordsToDocNumbers.get(word)); |
148 |
int[] docNumbers = readDocumentNumbers(docs); |
149 |
for (int i = 0, l = docNumbers.length; i < l; i++) { |
149 |
for (int i = 0, l = docNumbers.length; i < l; i++) { |
150 |
String docName = readDocumentName(docNumbers[i]); |
150 |
String docName = readDocumentName(docNumbers[i]); |
151 |
if (!docsToRefs.containsKey(docName)) |
151 |
if (!docsToRefs.containsKey(docName)) |
Lines 167-180
Link Here
|
167 |
boolean prevResults = false; |
167 |
boolean prevResults = false; |
168 |
if (key == null) { |
168 |
if (key == null) { |
169 |
for (int i = 0, l = categories.length; i < l; i++) { |
169 |
for (int i = 0, l = categories.length; i < l; i++) { |
170 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
170 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
171 |
if (wordsToDocNumbers != null) { |
171 |
if (wordsToDocNumbers != null) { |
172 |
char[][] words = wordsToDocNumbers.keyTable; |
172 |
char[][] words = wordsToDocNumbers.keyTable; |
|
|
173 |
Object[] values = wordsToDocNumbers.valueTable; |
173 |
if (results == null) |
174 |
if (results == null) |
174 |
results = new HashtableOfObject(wordsToDocNumbers.elementSize); |
175 |
results = new HashtableOfObject(wordsToDocNumbers.elementSize); |
175 |
for (int j = 0, m = words.length; j < m; j++) |
176 |
for (int j = 0, m = words.length; j < m; j++) |
176 |
if (words[j] != null) |
177 |
if (words[j] != null) |
177 |
results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex, prevResults); |
178 |
results = addQueryResult(results, words[j], values[j], memoryIndex, prevResults); |
178 |
} |
179 |
} |
179 |
prevResults = results != null; |
180 |
prevResults = results != null; |
180 |
} |
181 |
} |
Lines 184-204
Link Here
|
184 |
switch (matchRule) { |
185 |
switch (matchRule) { |
185 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
186 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
186 |
for (int i = 0, l = categories.length; i < l; i++) { |
187 |
for (int i = 0, l = categories.length; i < l; i++) { |
187 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
188 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
188 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) |
189 |
Object value; |
189 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex, prevResults); |
190 |
if (wordsToDocNumbers != null && (value = wordsToDocNumbers.get(key)) != null) |
|
|
191 |
results = addQueryResult(results, key, value, memoryIndex, prevResults); |
190 |
prevResults = results != null; |
192 |
prevResults = results != null; |
191 |
} |
193 |
} |
192 |
break; |
194 |
break; |
193 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
195 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
194 |
for (int i = 0, l = categories.length; i < l; i++) { |
196 |
for (int i = 0, l = categories.length; i < l; i++) { |
195 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
197 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
196 |
if (wordsToDocNumbers != null) { |
198 |
if (wordsToDocNumbers != null) { |
197 |
char[][] words = wordsToDocNumbers.keyTable; |
199 |
char[][] words = wordsToDocNumbers.keyTable; |
|
|
200 |
Object[] values = wordsToDocNumbers.valueTable; |
198 |
for (int j = 0, m = words.length; j < m; j++) { |
201 |
for (int j = 0, m = words.length; j < m; j++) { |
199 |
char[] word = words[j]; |
202 |
char[] word = words[j]; |
200 |
if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) |
203 |
if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) |
201 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, prevResults); |
204 |
results = addQueryResult(results, word, values[j], memoryIndex, prevResults); |
202 |
} |
205 |
} |
203 |
} |
206 |
} |
204 |
prevResults = results != null; |
207 |
prevResults = results != null; |
Lines 206-218
Link Here
|
206 |
break; |
209 |
break; |
207 |
default: |
210 |
default: |
208 |
for (int i = 0, l = categories.length; i < l; i++) { |
211 |
for (int i = 0, l = categories.length; i < l; i++) { |
209 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
212 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
210 |
if (wordsToDocNumbers != null) { |
213 |
if (wordsToDocNumbers != null) { |
211 |
char[][] words = wordsToDocNumbers.keyTable; |
214 |
char[][] words = wordsToDocNumbers.keyTable; |
|
|
215 |
Object[] values = wordsToDocNumbers.valueTable; |
212 |
for (int j = 0, m = words.length; j < m; j++) { |
216 |
for (int j = 0, m = words.length; j < m; j++) { |
213 |
char[] word = words[j]; |
217 |
char[] word = words[j]; |
214 |
if (word != null && Index.isMatch(key, word, matchRule)) |
218 |
if (word != null && Index.isMatch(key, word, matchRule)) |
215 |
results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, prevResults); |
219 |
results = addQueryResult(results, word, values[j], memoryIndex, prevResults); |
216 |
} |
220 |
} |
217 |
} |
221 |
} |
218 |
prevResults = results != null; |
222 |
prevResults = results != null; |
Lines 344-352
Link Here
|
344 |
char[] categoryName = categoryNames[i]; |
348 |
char[] categoryName = categoryNames[i]; |
345 |
if (categoryName != null) { |
349 |
if (categoryName != null) { |
346 |
SimpleWordSet wordSet = (SimpleWordSet) wordSets[i]; |
350 |
SimpleWordSet wordSet = (SimpleWordSet) wordSets[i]; |
347 |
CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); |
351 |
HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); |
348 |
if (wordsToDocs == null) |
352 |
if (wordsToDocs == null) |
349 |
this.categoryTables.put(categoryName, wordsToDocs = new CategoryTable(wordSet.elementSize)); |
353 |
this.categoryTables.put(categoryName, wordsToDocs = new HashtableOfObject(wordSet.elementSize)); |
350 |
|
354 |
|
351 |
char[][] words = wordSet.words; |
355 |
char[][] words = wordSet.words; |
352 |
for (int j = 0, m = words.length; j < m; j++) { |
356 |
for (int j = 0, m = words.length; j < m; j++) { |
Lines 450-460
Link Here
|
450 |
this.categoryTables = null; |
454 |
this.categoryTables = null; |
451 |
} |
455 |
} |
452 |
private void mergeCategory(char[] categoryName, DiskIndex onDisk, int[] positions, FileOutputStream stream) throws IOException { |
456 |
private void mergeCategory(char[] categoryName, DiskIndex onDisk, int[] positions, FileOutputStream stream) throws IOException { |
453 |
CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); |
457 |
HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); |
454 |
if (wordsToDocs == null) |
458 |
if (wordsToDocs == null) |
455 |
wordsToDocs = new CategoryTable(3); |
459 |
wordsToDocs = new HashtableOfObject(3); |
456 |
|
460 |
|
457 |
CategoryTable oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); |
461 |
HashtableOfObject oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); |
458 |
if (oldWordsToDocs != null) { |
462 |
if (oldWordsToDocs != null) { |
459 |
char[][] oldWords = oldWordsToDocs.keyTable; |
463 |
char[][] oldWords = oldWordsToDocs.keyTable; |
460 |
Object[] oldArrayOffsets = oldWordsToDocs.valueTable; |
464 |
Object[] oldArrayOffsets = oldWordsToDocs.valueTable; |
Lines 588-594
Link Here
|
588 |
this.streamBuffer = null; |
592 |
this.streamBuffer = null; |
589 |
} |
593 |
} |
590 |
} |
594 |
} |
591 |
private synchronized CategoryTable readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { |
595 |
private synchronized HashtableOfObject readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { |
592 |
// result will be null if categoryName is unknown |
596 |
// result will be null if categoryName is unknown |
593 |
int offset = this.categoryOffsets.get(categoryName); |
597 |
int offset = this.categoryOffsets.get(categoryName); |
594 |
if (offset == HashtableOfIntValues.NO_VALUE) { |
598 |
if (offset == HashtableOfIntValues.NO_VALUE) { |
Lines 598-604
Link Here
|
598 |
if (this.categoryTables == null) { |
602 |
if (this.categoryTables == null) { |
599 |
this.categoryTables = new HashtableOfObject(3); |
603 |
this.categoryTables = new HashtableOfObject(3); |
600 |
} else { |
604 |
} else { |
601 |
CategoryTable cachedTable = (CategoryTable) this.categoryTables.get(categoryName); |
605 |
HashtableOfObject cachedTable = (HashtableOfObject) this.categoryTables.get(categoryName); |
602 |
if (cachedTable != null) { |
606 |
if (cachedTable != null) { |
603 |
if (readDocNumbers) { // must cache remaining document number arrays |
607 |
if (readDocNumbers) { // must cache remaining document number arrays |
604 |
Object[] arrayOffsets = cachedTable.valueTable; |
608 |
Object[] arrayOffsets = cachedTable.valueTable; |
Lines 611-617
Link Here
|
611 |
} |
615 |
} |
612 |
|
616 |
|
613 |
FileInputStream stream = new FileInputStream(this.indexFile); |
617 |
FileInputStream stream = new FileInputStream(this.indexFile); |
614 |
CategoryTable categoryTable = null; |
618 |
HashtableOfObject categoryTable = null; |
615 |
char[][] matchingWords = null; |
619 |
char[][] matchingWords = null; |
616 |
int count = 0; |
620 |
int count = 0; |
617 |
int firstOffset = -1; |
621 |
int firstOffset = -1; |
Lines 629-635
Link Here
|
629 |
System.err.println("size = "+size); //$NON-NLS-1$ |
633 |
System.err.println("size = "+size); //$NON-NLS-1$ |
630 |
System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ |
634 |
System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ |
631 |
} |
635 |
} |
632 |
categoryTable = new CategoryTable(size); |
636 |
categoryTable = new HashtableOfObject(size); |
633 |
} catch (OutOfMemoryError oom) { |
637 |
} catch (OutOfMemoryError oom) { |
634 |
// DEBUG |
638 |
// DEBUG |
635 |
oom.printStackTrace(); |
639 |
oom.printStackTrace(); |
Lines 1038-1047
Link Here
|
1038 |
Object[] tables = this.categoryTables.valueTable; |
1042 |
Object[] tables = this.categoryTables.valueTable; |
1039 |
for (int i = 0, l = categoryNames.length; i < l; i++) |
1043 |
for (int i = 0, l = categoryNames.length; i < l; i++) |
1040 |
if (categoryNames[i] != null) |
1044 |
if (categoryNames[i] != null) |
1041 |
writeCategoryTable(categoryNames[i], (CategoryTable) tables[i], stream); |
1045 |
writeCategoryTable(categoryNames[i], (HashtableOfObject) tables[i], stream); |
1042 |
this.categoryTables = null; |
1046 |
this.categoryTables = null; |
1043 |
} |
1047 |
} |
1044 |
private void writeCategoryTable(char[] categoryName, CategoryTable wordsToDocs, FileOutputStream stream) throws IOException { |
1048 |
private void writeCategoryTable(char[] categoryName, HashtableOfObject wordsToDocs, FileOutputStream stream) throws IOException { |
1045 |
// the format of a category table is as follows: |
1049 |
// the format of a category table is as follows: |
1046 |
// any document number arrays with >= 256 elements are written before the table (the offset to each array is remembered) |
1050 |
// any document number arrays with >= 256 elements are written before the table (the offset to each array is remembered) |
1047 |
// then the number of word->int[] pairs in the table is written |
1051 |
// then the number of word->int[] pairs in the table is written |