Search in sources :

Example 1 with ShardSuggestRefreshResponse

use of de.spinscale.elasticsearch.action.suggest.refresh.ShardSuggestRefreshResponse 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());
}
Also used : ShardSuggestRefreshResponse(de.spinscale.elasticsearch.action.suggest.refresh.ShardSuggestRefreshResponse) HighFrequencyDictionary(org.apache.lucene.search.spell.HighFrequencyDictionary) SpellChecker(org.apache.lucene.search.spell.SpellChecker) FSTCompletionLookup(org.apache.lucene.search.suggest.fst.FSTCompletionLookup) IOException(java.io.IOException) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Aggregations

ShardSuggestRefreshResponse (de.spinscale.elasticsearch.action.suggest.refresh.ShardSuggestRefreshResponse)1 IOException (java.io.IOException)1 HighFrequencyDictionary (org.apache.lucene.search.spell.HighFrequencyDictionary)1 SpellChecker (org.apache.lucene.search.spell.SpellChecker)1 FSTCompletionLookup (org.apache.lucene.search.suggest.fst.FSTCompletionLookup)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1