Class LuceneQuerySuggester
- java.lang.Object
-
- de.cxp.ocs.smartsuggest.querysuggester.lucene.LuceneQuerySuggester
-
- All Implemented Interfaces:
Instrumentable,QueryIndexer,QuerySuggester,AutoCloseable,org.apache.lucene.util.Accountable
public class LuceneQuerySuggester extends Object implements QuerySuggester, QueryIndexer, org.apache.lucene.util.Accountable, Instrumentable
-
-
Field Summary
Fields Modifier and Type Field Description static StringBEST_MATCHES_GROUP_NAMEstatic StringFUZZY_MATCHES_ONE_EDIT_GROUP_NAMEstatic StringFUZZY_MATCHES_TWO_EDITS_GROUP_NAMEstatic StringPAYLOAD_GROUPMATCH_KEYstatic StringPAYLOAD_LABEL_KEYstatic StringRELAXED_GROUP_NAMEstatic StringSHARPENED_GROUP_NAMEstatic StringSHINGLE_MATCHES_GROUP_NAMEstatic StringTYPO_MATCHES_GROUP_NAME-
Fields inherited from interface de.cxp.ocs.smartsuggest.querysuggester.QuerySuggester
DEFAULT_MAXIMUM_RESULTS
-
-
Constructor Summary
Constructors Constructor Description LuceneQuerySuggester(@NonNull Path indexFolder, @NonNull Locale locale, @NonNull ModifiedTermsService modifiedTermsService, org.apache.lucene.analysis.CharArraySet stopWords)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voiddestroy()Destroys any resources created by this suggesterInstantgetLastIndexTime()CompletableFuture<Void>index(Iterable<SuggestRecord> suggestions)voidinstrument(Optional<MeterRegistryAdapter> metricsRegistryAdapter, Iterable<io.micrometer.core.instrument.Tag> tags)Optional meter registry (adapter that gives access to the actual meter-registry).booleanisReady()longramBytesUsed()longrecordCount()return amount of records indexed into this QuerySuggester.List<Suggestion>suggest(String term, int maxResults, Set<String> tags)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.cxp.ocs.smartsuggest.querysuggester.QuerySuggester
suggest
-
-
-
-
Field Detail
-
PAYLOAD_LABEL_KEY
public static final String PAYLOAD_LABEL_KEY
- See Also:
- Constant Field Values
-
PAYLOAD_GROUPMATCH_KEY
public static final String PAYLOAD_GROUPMATCH_KEY
- See Also:
- Constant Field Values
-
BEST_MATCHES_GROUP_NAME
public static final String BEST_MATCHES_GROUP_NAME
- See Also:
- Constant Field Values
-
TYPO_MATCHES_GROUP_NAME
public static final String TYPO_MATCHES_GROUP_NAME
- See Also:
- Constant Field Values
-
FUZZY_MATCHES_ONE_EDIT_GROUP_NAME
public static final String FUZZY_MATCHES_ONE_EDIT_GROUP_NAME
- See Also:
- Constant Field Values
-
FUZZY_MATCHES_TWO_EDITS_GROUP_NAME
public static final String FUZZY_MATCHES_TWO_EDITS_GROUP_NAME
- See Also:
- Constant Field Values
-
SHINGLE_MATCHES_GROUP_NAME
public static final String SHINGLE_MATCHES_GROUP_NAME
- See Also:
- Constant Field Values
-
RELAXED_GROUP_NAME
public static final String RELAXED_GROUP_NAME
- See Also:
- Constant Field Values
-
SHARPENED_GROUP_NAME
public static final String SHARPENED_GROUP_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LuceneQuerySuggester
public LuceneQuerySuggester(@NonNull @NonNull Path indexFolder, @NonNull @NonNull Locale locale, @NonNull @NonNull ModifiedTermsService modifiedTermsService, org.apache.lucene.analysis.CharArraySet stopWords)Constructor.- Parameters:
indexFolder- the parent folder for the specific suggesterslocale- the locale of the client. Used to load the proper stopwordsmodifiedTermsService- service that provides mappings for modified termsstopWords- optional set of stopwords. may be null
-
-
Method Detail
-
instrument
public void instrument(Optional<MeterRegistryAdapter> metricsRegistryAdapter, Iterable<io.micrometer.core.instrument.Tag> tags)
Description copied from interface:InstrumentableOptional meter registry (adapter that gives access to the actual meter-registry). If not available, no metrics should be measured.- Specified by:
instrumentin interfaceInstrumentabletags- these "standard" tags should be used for all added sensors. More tags can be added.
-
isReady
public boolean isReady()
- Specified by:
isReadyin interfaceQuerySuggester- Returns:
- true if ready to serve suggestions
-
suggest
public List<Suggestion> suggest(String term, int maxResults, Set<String> tags)
- Specified by:
suggestin interfaceQuerySuggester- Parameters:
term- the term for which to get suggestionsmaxResults- the maximum number of suggestions to returntags- the group names used for filtering- Returns:
- A list of suggestions for the given term
-
getLastIndexTime
public Instant getLastIndexTime()
- Specified by:
getLastIndexTimein interfaceQueryIndexer- Returns:
- The time of the last successful indexing
-
index
public CompletableFuture<Void> index(Iterable<SuggestRecord> suggestions)
- Specified by:
indexin interfaceQueryIndexer- Parameters:
suggestions- the suggestions to index- Returns:
- future that is ready as soon as the indexation is done
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
destroy
public void destroy()
Description copied from interface:QuerySuggesterDestroys any resources created by this suggester- Specified by:
destroyin interfaceQuerySuggester
-
ramBytesUsed
public long ramBytesUsed()
- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
recordCount
public long recordCount()
Description copied from interface:QuerySuggesterreturn amount of records indexed into this QuerySuggester.- Specified by:
recordCountin interfaceQuerySuggester- Returns:
- amount of indexed records
-
-