BlendedInfixSuggester (Lucene 10.5.0 suggest API)
Description: declaration: package: org.apache.lucene.search.suggest.analyzing, class: BlendedInfixSuggester

Package org.apache.lucene.search.suggest.analyzing

# Class BlendedInfixSuggester

java.lang.Object
org.apache.lucene.search.suggest.Lookup
org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
org.apache.lucene.search.suggest.analyzing.BlendedInfixSuggester

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `Accountable`

public class BlendedInfixSuggester extends AnalyzingInfixSuggester
Extension of the AnalyzingInfixSuggester which transforms the weight after search to take into account the position of the searched term into the indexed text. Please note that it increases the number of elements searched and applies the ponderation after. It might be costly for long suggestions.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `BlendedInfixSuggester.BlenderType`
  The different types of blender.

  ## Nested classes/interfaces inherited from class org.apache.lucene.search.suggest.Lookup

  `Lookup.LookupPriorityQueue, Lookup.LookupResult`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEFAULT_NUM_FACTOR`
  Default factor
  `protected static final double`
  `LINEAR_COEF`
  Coefficient used for linear blending

  ### Fields inherited from class org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester

  `CONTEXTS_FIELD_NAME, DEFAULT_ALL_TERMS_REQUIRED, DEFAULT_CLOSE_INDEXWRITER_ON_BUILD, DEFAULT_HIGHLIGHT, DEFAULT_MIN_PREFIX_CHARS, EXACT_TEXT_FIELD_NAME, indexAnalyzer, queryAnalyzer, searcherMgr, searcherMgrLock, TEXT_FIELD_NAME, TEXTGRAMS_FIELD_NAME, writer, writerLock`

  ### Fields inherited from class org.apache.lucene.search.suggest.Lookup

  `CHARSEQUENCE_COMPARATOR`

  ### Fields inherited from interface org.apache.lucene.util.Accountable

  `NULL_ACCOUNTABLE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BlendedInfixSuggester(Directory dir, Analyzer analyzer)`
  Create a new instance, loading from a previously built directory, if it exists.
  `BlendedInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, BlendedInfixSuggester.BlenderType blenderType, int numFactor, boolean commitOnBuild)`
  Create a new instance, loading from a previously built directory, if it exists.
  `BlendedInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, BlendedInfixSuggester.BlenderType blenderType, int numFactor, Double exponent, boolean commitOnBuild, boolean allTermsRequired, boolean highlight)`
  Create a new instance, loading from a previously built directory, if it exists.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected double`
  `calculateCoefficient(int position)`
  Calculate the weight coefficient based on the position of the first matching word.
  `protected List<Lookup.LookupResult>`
  `createResults(IndexSearcher searcher, TopFieldDocs hits, int num, CharSequence key, boolean doHighlight, Set<String> matchedTokens, String prefixToken)`
  Create the results based on the search hits.
  `protected FieldType`
  `getTextFieldType()`
  Subclass can override this method to change the field type of the text field e.g.
  `List<Lookup.LookupResult>`
  `lookup(CharSequence key, Map<BytesRef,BooleanClause.Occur> contextInfo, int num, boolean allTermsRequired, boolean doHighlight)`
  Retrieve suggestions, specifying whether all terms must match (`allTermsRequired`) and whether the hits should be highlighted (`doHighlight`).
  `List<Lookup.LookupResult>`
  `lookup(CharSequence key, Set<BytesRef> contexts, boolean onlyMorePopular, int num)`
  Look up a key and return possible completion for this key.
  `List<Lookup.LookupResult>`
  `lookup(CharSequence key, Set<BytesRef> contexts, int num, boolean allTermsRequired, boolean doHighlight)`
  Lookup, with context but without booleans.
  `List<Lookup.LookupResult>`
  `lookup(CharSequence key, BooleanQuery contextQuery, int num, boolean allTermsRequired, boolean doHighlight)`
  This is an advanced method providing the capability to send down to the suggester any arbitrary lucene query to be used to filter the result of the suggester

  ### Methods inherited from class org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester

  `add, addContextToQuery, addNonMatch, addPrefixMatch, addWholeMatch, build, close, commit, finishQuery, getCount, getDirectory, getIndexWriterConfig, getLastTokenQuery, highlight, load, lookup, ramBytesUsed, refresh, store, update`

  ### Methods inherited from class org.apache.lucene.search.suggest.Lookup

  `build, load, lookup, store`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.lucene.util.Accountable

  `getChildResources`

- ## Field Details

  - ### LINEAR_COEF

    protected static final double LINEAR_COEF
    Coefficient used for linear blending
    See Also:
      - Constant Field Values

  - ### DEFAULT_NUM_FACTOR

    public static final int DEFAULT_NUM_FACTOR
    Default factor
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### BlendedInfixSuggester

    public BlendedInfixSuggester(Directory dir, Analyzer analyzer) throws IOException
    Create a new instance, loading from a previously built directory, if it exists.
    Throws:
      `IOException`

  - ### BlendedInfixSuggester

    public BlendedInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, BlendedInfixSuggester.BlenderType blenderType, int numFactor, boolean commitOnBuild) throws IOException
    Create a new instance, loading from a previously built directory, if it exists.
    Parameters:
      `blenderType` - Type of blending strategy, see BlenderType for more precisions
      `numFactor` - Factor to multiply the number of searched elements before ponderate
      `commitOnBuild` - Call commit after the index has finished building. This would persist the suggester index to disk and future instances of this suggester can use this pre-built dictionary.
    Throws:
      `IOException` - If there are problems opening the underlying Lucene index.

  - ### BlendedInfixSuggester

    public BlendedInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, BlendedInfixSuggester.BlenderType blenderType, int numFactor, Double exponent, boolean commitOnBuild, boolean allTermsRequired, boolean highlight) throws IOException
    Create a new instance, loading from a previously built directory, if it exists.
    Parameters:
      `blenderType` - Type of blending strategy, see BlenderType for more precisions
      `numFactor` - Factor to multiply the number of searched elements before ponderate
      `exponent` - exponent used only when blenderType is BlenderType.POSITION_EXPONENTIAL_RECIPROCAL
      `commitOnBuild` - Call commit after the index has finished building. This would persist the suggester index to disk and future instances of this suggester can use this pre-built dictionary.
      `allTermsRequired` - All terms in the suggest query must be matched.
      `highlight` - Highlight suggest query in suggestions.
    Throws:
      `IOException` - If there are problems opening the underlying Lucene index.

- ## Method Details

  - ### lookup

    public List<Lookup.LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, boolean onlyMorePopular, int num) throws IOException
    Description copied from class: `Lookup`
    Look up a key and return possible completion for this key.
    Overrides:
      `lookup` in class `AnalyzingInfixSuggester`
    Parameters:
      `key` - lookup key. Depending on the implementation this may be a prefix, misspelling, or even infix.
      `contexts` - contexts to filter the lookup by, or null if all contexts are allowed; if the suggestion contains any of the contexts, it's a match
      `onlyMorePopular` - return only more popular results
      `num` - maximum number of results to return
    Returns:
      a list of possible completions, with their relative weight (e.g. popularity)
    Throws:
      `IOException`

  - ### lookup

    public List<Lookup.LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, int num, boolean allTermsRequired, boolean doHighlight) throws IOException
    Description copied from class: `AnalyzingInfixSuggester`
    Lookup, with context but without booleans. Context booleans default to SHOULD, so each suggestion must have at least one of the contexts.
    Overrides:
      `lookup` in class `AnalyzingInfixSuggester`
    Throws:
      `IOException`

  - ### lookup

    public List<Lookup.LookupResult> lookup(CharSequence key, Map<BytesRef,BooleanClause.Occur> contextInfo, int num, boolean allTermsRequired, boolean doHighlight) throws IOException
    Description copied from class: `AnalyzingInfixSuggester`
    Retrieve suggestions, specifying whether all terms must match (`allTermsRequired`) and whether the hits should be highlighted (`doHighlight`).
    Overrides:
      `lookup` in class `AnalyzingInfixSuggester`
    Throws:
      `IOException`

  - ### lookup

    public List<Lookup.LookupResult> lookup(CharSequence key, BooleanQuery contextQuery, int num, boolean allTermsRequired, boolean doHighlight) throws IOException
    Description copied from class: `AnalyzingInfixSuggester`
    This is an advanced method providing the capability to send down to the suggester any arbitrary lucene query to be used to filter the result of the suggester
    Overrides:
      `lookup` in class `AnalyzingInfixSuggester`
    Parameters:
      `key` - the keyword being looked for
      `contextQuery` - an arbitrary Lucene query to be used to filter the result of the suggester. `AnalyzingInfixSuggester.addContextToQuery(org.apache.lucene.search.BooleanQuery.Builder, org.apache.lucene.util.BytesRef, org.apache.lucene.search.BooleanClause.Occur)` could be used to build this contextQuery.
      `num` - number of items to return
      `allTermsRequired` - all searched terms must match or not
      `doHighlight` - if true, the matching term will be highlighted in the search result
    Returns:
      the result of the suggester
    Throws:
      `IOException` - f the is IO exception while reading data from the index

  - ### getTextFieldType

    protected FieldType getTextFieldType()
    Description copied from class: `AnalyzingInfixSuggester`
    Subclass can override this method to change the field type of the text field e.g. to change the index options
    Overrides:
      `getTextFieldType` in class `AnalyzingInfixSuggester`

  - ### createResults

    protected List<Lookup.LookupResult> createResults(IndexSearcher searcher, TopFieldDocs hits, int num, CharSequence key, boolean doHighlight, Set<String> matchedTokens, String prefixToken) throws IOException
    Description copied from class: `AnalyzingInfixSuggester`
    Create the results based on the search hits. Can be overridden by subclass to add particular behavior (e.g. weight transformation). Note that there is no prefix token (the `prefixToken` argument will be null) whenever the final token in the incoming request was in fact finished (had trailing characters, such as white-space).
    Overrides:
      `createResults` in class `AnalyzingInfixSuggester`
    Throws:
      `IOException` - If there are problems reading fields from the underlying Lucene index.

  - ### calculateCoefficient

    protected double calculateCoefficient(int position)
    Calculate the weight coefficient based on the position of the first matching word. Subclass should override it to adapt it to particular needs
    Parameters:
      `position` - of the first matching word in text
    Returns:
      the coefficient