Lines 132-138
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, HashtableOfObject wordsToDocNumbers, MemoryIndex memoryIndex) 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); |
Lines 163-169
Link Here
|
163 |
HashtableOfObject results = null; // initialized if needed |
163 |
HashtableOfObject results = null; // initialized if needed |
164 |
if (key == null) { |
164 |
if (key == null) { |
165 |
for (int i = 0, l = categories.length; i < l; i++) { |
165 |
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 |
166 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
167 |
if (wordsToDocNumbers != null) { |
167 |
if (wordsToDocNumbers != null) { |
168 |
char[][] words = wordsToDocNumbers.keyTable; |
168 |
char[][] words = wordsToDocNumbers.keyTable; |
169 |
if (results == null) |
169 |
if (results == null) |
Lines 179-192
Link Here
|
179 |
switch (matchRule) { |
179 |
switch (matchRule) { |
180 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
180 |
case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: |
181 |
for (int i = 0, l = categories.length; i < l; i++) { |
181 |
for (int i = 0, l = categories.length; i < l; i++) { |
182 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
182 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
183 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) |
183 |
if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) |
184 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex); |
184 |
results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex); |
185 |
} |
185 |
} |
186 |
break; |
186 |
break; |
187 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
187 |
case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: |
188 |
for (int i = 0, l = categories.length; i < l; i++) { |
188 |
for (int i = 0, l = categories.length; i < l; i++) { |
189 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
189 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
190 |
if (wordsToDocNumbers != null) { |
190 |
if (wordsToDocNumbers != null) { |
191 |
char[][] words = wordsToDocNumbers.keyTable; |
191 |
char[][] words = wordsToDocNumbers.keyTable; |
192 |
for (int j = 0, m = words.length; j < m; j++) { |
192 |
for (int j = 0, m = words.length; j < m; j++) { |
Lines 199-205
Link Here
|
199 |
break; |
199 |
break; |
200 |
default: |
200 |
default: |
201 |
for (int i = 0, l = categories.length; i < l; i++) { |
201 |
for (int i = 0, l = categories.length; i < l; i++) { |
202 |
CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); |
202 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
203 |
if (wordsToDocNumbers != null) { |
203 |
if (wordsToDocNumbers != null) { |
204 |
char[][] words = wordsToDocNumbers.keyTable; |
204 |
char[][] words = wordsToDocNumbers.keyTable; |
205 |
for (int j = 0, m = words.length; j < m; j++) { |
205 |
for (int j = 0, m = words.length; j < m; j++) { |
Lines 336-344
Link Here
|
336 |
char[] categoryName = categoryNames[i]; |
336 |
char[] categoryName = categoryNames[i]; |
337 |
if (categoryName != null) { |
337 |
if (categoryName != null) { |
338 |
SimpleWordSet wordSet = (SimpleWordSet) wordSets[i]; |
338 |
SimpleWordSet wordSet = (SimpleWordSet) wordSets[i]; |
339 |
CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); |
339 |
HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); |
340 |
if (wordsToDocs == null) |
340 |
if (wordsToDocs == null) |
341 |
this.categoryTables.put(categoryName, wordsToDocs = new CategoryTable(wordSet.elementSize)); |
341 |
this.categoryTables.put(categoryName, wordsToDocs = new HashtableOfObject(wordSet.elementSize)); |
342 |
|
342 |
|
343 |
char[][] words = wordSet.words; |
343 |
char[][] words = wordSet.words; |
344 |
for (int j = 0, m = words.length; j < m; j++) { |
344 |
for (int j = 0, m = words.length; j < m; j++) { |
Lines 442-452
Link Here
|
442 |
this.categoryTables = null; |
442 |
this.categoryTables = null; |
443 |
} |
443 |
} |
444 |
private void mergeCategory(char[] categoryName, DiskIndex onDisk, int[] positions, FileOutputStream stream) throws IOException { |
444 |
private void mergeCategory(char[] categoryName, DiskIndex onDisk, int[] positions, FileOutputStream stream) throws IOException { |
445 |
CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); |
445 |
HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); |
446 |
if (wordsToDocs == null) |
446 |
if (wordsToDocs == null) |
447 |
wordsToDocs = new CategoryTable(3); |
447 |
wordsToDocs = new HashtableOfObject(3); |
448 |
|
448 |
|
449 |
CategoryTable oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); |
449 |
HashtableOfObject oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); |
450 |
if (oldWordsToDocs != null) { |
450 |
if (oldWordsToDocs != null) { |
451 |
char[][] oldWords = oldWordsToDocs.keyTable; |
451 |
char[][] oldWords = oldWordsToDocs.keyTable; |
452 |
Object[] oldArrayOffsets = oldWordsToDocs.valueTable; |
452 |
Object[] oldArrayOffsets = oldWordsToDocs.valueTable; |
Lines 580-586
Link Here
|
580 |
this.streamBuffer = null; |
580 |
this.streamBuffer = null; |
581 |
} |
581 |
} |
582 |
} |
582 |
} |
583 |
private synchronized CategoryTable readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { |
583 |
private synchronized HashtableOfObject readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { |
584 |
// result will be null if categoryName is unknown |
584 |
// result will be null if categoryName is unknown |
585 |
int offset = this.categoryOffsets.get(categoryName); |
585 |
int offset = this.categoryOffsets.get(categoryName); |
586 |
if (offset == HashtableOfIntValues.NO_VALUE) { |
586 |
if (offset == HashtableOfIntValues.NO_VALUE) { |
Lines 590-596
Link Here
|
590 |
if (this.categoryTables == null) { |
590 |
if (this.categoryTables == null) { |
591 |
this.categoryTables = new HashtableOfObject(3); |
591 |
this.categoryTables = new HashtableOfObject(3); |
592 |
} else { |
592 |
} else { |
593 |
CategoryTable cachedTable = (CategoryTable) this.categoryTables.get(categoryName); |
593 |
HashtableOfObject cachedTable = (HashtableOfObject) this.categoryTables.get(categoryName); |
594 |
if (cachedTable != null) { |
594 |
if (cachedTable != null) { |
595 |
if (readDocNumbers) { // must cache remaining document number arrays |
595 |
if (readDocNumbers) { // must cache remaining document number arrays |
596 |
Object[] arrayOffsets = cachedTable.valueTable; |
596 |
Object[] arrayOffsets = cachedTable.valueTable; |
Lines 603-609
Link Here
|
603 |
} |
603 |
} |
604 |
|
604 |
|
605 |
FileInputStream stream = new FileInputStream(this.indexFile); |
605 |
FileInputStream stream = new FileInputStream(this.indexFile); |
606 |
CategoryTable categoryTable = null; |
606 |
HashtableOfObject categoryTable = null; |
607 |
char[][] matchingWords = null; |
607 |
char[][] matchingWords = null; |
608 |
int count = 0; |
608 |
int count = 0; |
609 |
int firstOffset = -1; |
609 |
int firstOffset = -1; |
Lines 621-627
Link Here
|
621 |
System.err.println("size = "+size); //$NON-NLS-1$ |
621 |
System.err.println("size = "+size); //$NON-NLS-1$ |
622 |
System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ |
622 |
System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ |
623 |
} |
623 |
} |
624 |
categoryTable = new CategoryTable(size); |
624 |
if (size > 1024) { |
|
|
625 |
categoryTable = new CategoryTable(size); |
626 |
} else { |
627 |
categoryTable = new HashtableOfObject(size); |
628 |
} |
625 |
} catch (OutOfMemoryError oom) { |
629 |
} catch (OutOfMemoryError oom) { |
626 |
// DEBUG |
630 |
// DEBUG |
627 |
oom.printStackTrace(); |
631 |
oom.printStackTrace(); |
Lines 1030-1039
Link Here
|
1030 |
Object[] tables = this.categoryTables.valueTable; |
1034 |
Object[] tables = this.categoryTables.valueTable; |
1031 |
for (int i = 0, l = categoryNames.length; i < l; i++) |
1035 |
for (int i = 0, l = categoryNames.length; i < l; i++) |
1032 |
if (categoryNames[i] != null) |
1036 |
if (categoryNames[i] != null) |
1033 |
writeCategoryTable(categoryNames[i], (CategoryTable) tables[i], stream); |
1037 |
writeCategoryTable(categoryNames[i], (HashtableOfObject) tables[i], stream); |
1034 |
this.categoryTables = null; |
1038 |
this.categoryTables = null; |
1035 |
} |
1039 |
} |
1036 |
private void writeCategoryTable(char[] categoryName, CategoryTable wordsToDocs, FileOutputStream stream) throws IOException { |
1040 |
private void writeCategoryTable(char[] categoryName, HashtableOfObject wordsToDocs, FileOutputStream stream) throws IOException { |
1037 |
// the format of a category table is as follows: |
1041 |
// the format of a category table is as follows: |
1038 |
// any document number arrays with >= 256 elements are written before the table (the offset to each array is remembered) |
1042 |
// any document number arrays with >= 256 elements are written before the table (the offset to each array is remembered) |
1039 |
// then the number of word->int[] pairs in the table is written |
1043 |
// then the number of word->int[] pairs in the table is written |