use of org.apache.lucene.search.suggest.fst.FSTCompletionLookup in project elasticsearch-suggest-plugin by spinscale.
the class ShardSuggestService method refresh.
public ShardSuggestRefreshResponse refresh(ShardSuggestRefreshRequest shardSuggestRefreshRequest) {
String field = shardSuggestRefreshRequest.field();
if (!Strings.hasLength(field)) {
update();
} else {
resetIndexReader();
HighFrequencyDictionary dict = dictCache.getIfPresent(field);
if (dict != null)
dictCache.refresh(field);
RAMDirectory ramDirectory = ramDirectoryCache.getIfPresent(field);
if (ramDirectory != null) {
ramDirectory.close();
ramDirectoryCache.invalidate(field);
}
SpellChecker spellChecker = spellCheckerCache.getIfPresent(field);
if (spellChecker != null) {
spellCheckerCache.refresh(field);
try {
spellChecker.close();
} catch (IOException e) {
logger.error("Could not close spellchecker in indexshard [{}] for field [{}]", e, indexShard, field);
}
}
FSTCompletionLookup lookup = lookupCache.getIfPresent(field);
if (lookup != null)
lookupCache.refresh(field);
for (FieldType fieldType : analyzingSuggesterCache.asMap().keySet()) {
if (fieldType.field().equals(shardSuggestRefreshRequest.field())) {
analyzingSuggesterCache.refresh(fieldType);
}
}
for (FieldType fieldType : fuzzySuggesterCache.asMap().keySet()) {
if (fieldType.field().equals(shardSuggestRefreshRequest.field())) {
fuzzySuggesterCache.refresh(fieldType);
}
}
}
return new ShardSuggestRefreshResponse(shardId.index().name(), shardId.id());
}
use of org.apache.lucene.search.suggest.fst.FSTCompletionLookup in project lucene-solr by apache.
the class PersistenceTest method runTest.
private void runTest(Class<? extends Lookup> lookupClass, boolean supportsExactWeights) throws Exception {
// Add all input keys.
Lookup lookup;
Directory tempDir = getDirectory();
if (lookupClass == TSTLookup.class) {
lookup = new TSTLookup(tempDir, "suggest");
} else if (lookupClass == FSTCompletionLookup.class) {
lookup = new FSTCompletionLookup(tempDir, "suggest");
} else {
lookup = lookupClass.newInstance();
}
Input[] keys = new Input[this.keys.length];
for (int i = 0; i < keys.length; i++) keys[i] = new Input(this.keys[i], i);
lookup.build(new InputArrayIterator(keys));
// Store the suggester.
Path storeDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
lookup.store(Files.newOutputStream(storeDir.resolve("lookup.dat")));
// Re-read it from disk.
lookup = lookupClass.newInstance();
lookup.load(Files.newInputStream(storeDir.resolve("lookup.dat")));
// Assert validity.
Random random = random();
long previous = Long.MIN_VALUE;
for (Input k : keys) {
List<LookupResult> list = lookup.lookup(TestUtil.bytesToCharSequence(k.term, random), false, 1);
assertEquals(1, list.size());
LookupResult lookupResult = list.get(0);
assertNotNull(k.term.utf8ToString(), lookupResult.key);
if (supportsExactWeights) {
assertEquals(k.term.utf8ToString(), k.v, lookupResult.value);
} else {
assertTrue(lookupResult.value + ">=" + previous, lookupResult.value >= previous);
previous = lookupResult.value;
}
}
tempDir.close();
}
Aggregations