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 Details

  • Constructor Details

    • LuceneQuerySuggester

      public LuceneQuerySuggester(Path indexFolder, SuggestConfig suggestConfig, ModifiedTermsService modifiedTermsService, org.apache.lucene.analysis.CharArraySet stopWords)
      Constructor for fresh suggester that in initialized in an empty folder. To recover the suggester, use the other constructor with the modTime of the according data.
      Parameters:
      indexFolder - the parent folder for the specific suggesters
      suggestConfig - the full suggest configuration
      modifiedTermsService - service that provides mappings for modified terms
      stopWords - optional set of stopwords. may be null
    • LuceneQuerySuggester

      public LuceneQuerySuggester(Path indexFolder, SuggestConfig suggestConfig, ModifiedTermsService modifiedTermsService, org.apache.lucene.analysis.CharArraySet stopWords, Long modTime)
      Constructor.
      Parameters:
      indexFolder - the parent folder for the specific suggesters
      suggestConfig - the full suggest configuration
      modifiedTermsService - service that provides mappings for modified terms
      stopWords - optional set of stopwords. may be null
      modTime - Value that only MUST be set, if the indexFolder already contains the indexed data. It MUST NOT be set, if the indexFolder is empty and does not contain data. This modTime relates to the data that is already in the indexFolder.
  • Method Details

    • instrument

      public void instrument(MeterRegistryAdapter metricsRegistryAdapter, Iterable<io.micrometer.core.instrument.Tag> tags)
      Description copied from interface: Instrumentable
      Optional meter registry (adapter that gives access to the actual meter-registry). If not available, no metrics should be measured.
      Specified by:
      instrument in interface Instrumentable
      Parameters:
      metricsRegistryAdapter - optional adapter
      tags - these "standard" tags should be used for all added sensors. More tags can be added.
    • isReady

      public boolean isReady()
      Specified by:
      isReady in interface QuerySuggester
      Returns:
      true if ready to serve suggestions
    • suggest

      public List<Suggestion> suggest(String term, int maxResults, Set<String> tags)
      Specified by:
      suggest in interface QuerySuggester
      Parameters:
      term - the term for which to get suggestions
      maxResults - the maximum number of suggestions to return
      tags - the group names used for filtering
      Returns:
      A list of suggestions for the given term
    • index

      public CompletableFuture<Void> index(Iterable<SuggestRecord> suggestions, long modificationTime)
      Specified by:
      index in interface QueryIndexer
      Parameters:
      suggestions - the suggestions to index
      modificationTime - timestamp (millis) of the data origin
      Returns:
      future that is ready as soon as the indexation is done
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • destroy

      public void destroy() throws Exception
      Description copied from interface: QuerySuggester
      Destroys any resources created by this suggester
      Specified by:
      destroy in interface QuerySuggester
      Throws:
      Exception
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface org.apache.lucene.util.Accountable
    • recordCount

      public long recordCount()
      Description copied from interface: QuerySuggester
      return amount of records indexed into this QuerySuggester.
      Specified by:
      recordCount in interface QuerySuggester
      Returns:
      amount of indexed records