Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 132-145
Link Here
|
132 |
} |
132 |
} |
133 |
return results; |
133 |
return results; |
134 |
} |
134 |
} |
135 |
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, HashtableOfObject wordsToDocNumbers, MemoryIndex memoryIndex) throws IOException { |
135 |
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable 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); |
139 |
EntryResult result = (EntryResult) results.get(word); |
139 |
EntryResult result = (EntryResult) results.get(word); |
140 |
if (memoryIndex == null) { |
140 |
if (memoryIndex == null) { |
141 |
if (result == null) |
141 |
if (result == null) |
142 |
results.put(word, new EntryResult(word, wordsToDocNumbers)); |
142 |
results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); |
143 |
else |
143 |
else |
144 |
result.addDocumentTable(wordsToDocNumbers); |
144 |
result.addDocumentTable(wordsToDocNumbers); |
145 |
} else { |
145 |
} else { |
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 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match |
166 |
CategoryTable 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 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
182 |
CategoryTable 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 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
189 |
CategoryTable 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 |
HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); |
202 |
CategoryTable 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 |
HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); |
339 |
CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); |
340 |
if (wordsToDocs == null) |
340 |
if (wordsToDocs == null) |
341 |
this.categoryTables.put(categoryName, wordsToDocs = new HashtableOfObject(wordSet.elementSize)); |
341 |
this.categoryTables.put(categoryName, wordsToDocs = new CategoryTable(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 346-352
Link Here
|
346 |
if (word != null) { |
346 |
if (word != null) { |
347 |
Object o = wordsToDocs.get(word); |
347 |
Object o = wordsToDocs.get(word); |
348 |
if (o == null) { |
348 |
if (o == null) { |
349 |
wordsToDocs.put(word, new int[] {newPosition}); |
349 |
wordsToDocs.putUnsafely(word, new int[] {newPosition}); |
350 |
} else if (o instanceof IntList) { |
350 |
} else if (o instanceof IntList) { |
351 |
((IntList) o).add(newPosition); |
351 |
((IntList) o).add(newPosition); |
352 |
} else { |
352 |
} else { |
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 |
HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); |
445 |
CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); |
446 |
if (wordsToDocs == null) |
446 |
if (wordsToDocs == null) |
447 |
wordsToDocs = new HashtableOfObject(3); |
447 |
wordsToDocs = new CategoryTable(3); |
448 |
|
448 |
|
449 |
HashtableOfObject oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); |
449 |
CategoryTable 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 469-475
Link Here
|
469 |
|
469 |
|
470 |
Object o = wordsToDocs.get(oldWord); |
470 |
Object o = wordsToDocs.get(oldWord); |
471 |
if (o == null) { |
471 |
if (o == null) { |
472 |
wordsToDocs.put(oldWord, mappedNumbers); |
472 |
wordsToDocs.putUnsafely(oldWord, mappedNumbers); |
473 |
} else { |
473 |
} else { |
474 |
IntList list = null; |
474 |
IntList list = null; |
475 |
if (o instanceof IntList) { |
475 |
if (o instanceof IntList) { |
Lines 580-586
Link Here
|
580 |
this.streamBuffer = null; |
580 |
this.streamBuffer = null; |
581 |
} |
581 |
} |
582 |
} |
582 |
} |
583 |
private synchronized HashtableOfObject readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { |
583 |
private synchronized CategoryTable 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 |
HashtableOfObject cachedTable = (HashtableOfObject) this.categoryTables.get(categoryName); |
593 |
CategoryTable cachedTable = (CategoryTable) 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 |
HashtableOfObject categoryTable = null; |
606 |
CategoryTable 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 HashtableOfObject(size); |
624 |
categoryTable = new CategoryTable(size); |
625 |
} catch (OutOfMemoryError oom) { |
625 |
} catch (OutOfMemoryError oom) { |
626 |
// DEBUG |
626 |
// DEBUG |
627 |
oom.printStackTrace(); |
627 |
oom.printStackTrace(); |
Lines 641-649
Link Here
|
641 |
// > 1 & < 256 then the size of the array is > 1 & < 256, the document array follows immediately |
641 |
// > 1 & < 256 then the size of the array is > 1 & < 256, the document array follows immediately |
642 |
// 256 if the array size >= 256 followed by another int which is the offset to the array (written prior to the table) |
642 |
// 256 if the array size >= 256 followed by another int which is the offset to the array (written prior to the table) |
643 |
if (arrayOffset <= 0) { |
643 |
if (arrayOffset <= 0) { |
644 |
categoryTable.put(word, new int[] {-arrayOffset}); // store 1 element array by negating documentNumber |
644 |
categoryTable.putUnsafely(word, new int[] {-arrayOffset}); // store 1 element array by negating documentNumber |
645 |
} else if (arrayOffset < largeArraySize) { |
645 |
} else if (arrayOffset < largeArraySize) { |
646 |
categoryTable.put(word, readStreamDocumentArray(stream, arrayOffset)); // read in-lined array providing size |
646 |
categoryTable.putUnsafely(word, readStreamDocumentArray(stream, arrayOffset)); // read in-lined array providing size |
647 |
} else { |
647 |
} else { |
648 |
arrayOffset = readStreamInt(stream); // read actual offset |
648 |
arrayOffset = readStreamInt(stream); // read actual offset |
649 |
if (readDocNumbers) { |
649 |
if (readDocNumbers) { |
Lines 653-659
Link Here
|
653 |
firstOffset = arrayOffset; |
653 |
firstOffset = arrayOffset; |
654 |
matchingWords[count++] = word; |
654 |
matchingWords[count++] = word; |
655 |
} |
655 |
} |
656 |
categoryTable.put(word, new Integer(arrayOffset)); // offset to array in the file |
656 |
categoryTable.putUnsafely(word, new Integer(arrayOffset)); // offset to array in the file |
657 |
} |
657 |
} |
658 |
} |
658 |
} |
659 |
this.categoryTables.put(INTERNED_CATEGORY_NAMES.get(categoryName), categoryTable); |
659 |
this.categoryTables.put(INTERNED_CATEGORY_NAMES.get(categoryName), categoryTable); |
Lines 1030-1039
Link Here
|
1030 |
Object[] tables = this.categoryTables.valueTable; |
1030 |
Object[] tables = this.categoryTables.valueTable; |
1031 |
for (int i = 0, l = categoryNames.length; i < l; i++) |
1031 |
for (int i = 0, l = categoryNames.length; i < l; i++) |
1032 |
if (categoryNames[i] != null) |
1032 |
if (categoryNames[i] != null) |
1033 |
writeCategoryTable(categoryNames[i], (HashtableOfObject) tables[i], stream); |
1033 |
writeCategoryTable(categoryNames[i], (CategoryTable) tables[i], stream); |
1034 |
this.categoryTables = null; |
1034 |
this.categoryTables = null; |
1035 |
} |
1035 |
} |
1036 |
private void writeCategoryTable(char[] categoryName, HashtableOfObject wordsToDocs, FileOutputStream stream) throws IOException { |
1036 |
private void writeCategoryTable(char[] categoryName, CategoryTable wordsToDocs, FileOutputStream stream) throws IOException { |
1037 |
// the format of a category table is as follows: |
1037 |
// 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) |
1038 |
// 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 |
1039 |
// then the number of word->int[] pairs in the table is written |