Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class AnalyzingSuggester

    Suggester that first analyzes the surface form, adds the analyzed form to a weighted FST, and then does the same thing at lookup time. This means lookup is based on the analyzed form while suggestions are still the surface form(s).

    This can result in powerful suggester functionality. For example, if you use an analyzer removing stop words, then the partial text "ghost chr..." could see the suggestion "The Ghost of Christmas Past". Note that position increments MUST NOT be preserved for this example to work, so you should call the constructor with preservePositionIncrements parameter set to false

    If SynonymFilter is used to map wifi and wireless network to hotspot then the partial text "wirele..." could suggest "wifi router". Token normalization like stemmers, accent removal, etc., would allow suggestions to ignore such variations.

    When two matching suggestions have the same weight, they are tie-broken by the analyzed form. If their analyzed form is the same then the order is undefined.

    There are some limitations:

    1. A lookup from a query like "net" in English won't be any different than "net " (ie, user added a trailing space) because analyzers don't reflect when they've seen a token separator and when they haven't.
    2. If you're using Lucene.Net.Analysis.Core.StopFilter, and the user will type "fast apple", but so far all they've typed is "fast a", again because the analyzer doesn't convey whether it's seen a token separator after the "a", Lucene.Net.Analysis.Core.StopFilter will remove that "a" causing far more matches than you'd expect.
    3. Lookups with the empty string return no results instead of all results.

    Note

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

    Inheritance
    object
    Lookup
    AnalyzingSuggester
    FuzzySuggester
    Inherited Members
    Lookup.CHARSEQUENCE_COMPARER
    Lookup.Build(IDictionary)
    Lookup.Load(Stream)
    Lookup.Store(Stream)
    Lookup.DoLookup(string, bool, int)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Search.Suggest.Analyzing
    Assembly: Lucene.Net.Suggest.dll
    Syntax
    public class AnalyzingSuggester : Lookup

    Constructors

    AnalyzingSuggester(Analyzer)

    Calls AnalyzingSuggester(analyzer, analyzer, SuggesterOptions.EXACT_FIRST | SuggesterOptions.PRESERVE_SEP, 256, -1, true)

    Declaration
    public AnalyzingSuggester(Analyzer analyzer)
    Parameters
    Type Name Description
    Analyzer analyzer

    AnalyzingSuggester(Analyzer, Analyzer)

    Calls AnalyzingSuggester(indexAnalyzer, queryAnalyzer, SuggesterOptions.EXACT_FIRST | SuggesterOptions.PRESERVE_SEP, 256, -1, true)

    Declaration
    public AnalyzingSuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer)
    Parameters
    Type Name Description
    Analyzer indexAnalyzer
    Analyzer queryAnalyzer

    AnalyzingSuggester(Analyzer, Analyzer, SuggesterOptions, int, int, bool)

    Creates a new suggester.

    Declaration
    public AnalyzingSuggester(Analyzer indexAnalyzer, Analyzer queryAnalyzer, SuggesterOptions options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions, bool preservePositionIncrements)
    Parameters
    Type Name Description
    Analyzer indexAnalyzer

    Analyzer that will be used for analyzing suggestions while building the index.

    Analyzer queryAnalyzer

    Analyzer that will be used for analyzing query text during lookup

    SuggesterOptions options

    see EXACT_FIRST, PRESERVE_SEP

    int maxSurfaceFormsPerAnalyzedForm

    Maximum number of surface forms to keep for a single analyzed form. When there are too many surface forms we discard the lowest weighted ones.

    int maxGraphExpansions

    Maximum number of graph paths to expand from the analyzed form. Set this to -1 for no limit.

    bool preservePositionIncrements

    Whether position holes should appear in the automata

    Properties

    Count

    Get the number of entries the lookup was built with

    Declaration
    public override long Count { get; }
    Property Value
    Type Description
    long

    total number of suggester entries

    Overrides
    Lookup.Count

    Methods

    Build(IInputEnumerator)

    Builds up a new internal Lookup representation based on the given IInputEnumerator. The implementation might re-sort the data internally.

    Declaration
    public override void Build(IInputEnumerator enumerator)
    Parameters
    Type Name Description
    IInputEnumerator enumerator
    Overrides
    Lookup.Build(IInputEnumerator)

    ConvertAutomaton(Automaton)

    Used by subclass to change the lookup automaton, if necessary.

    Declaration
    protected virtual Automaton ConvertAutomaton(Automaton a)
    Parameters
    Type Name Description
    Automaton a
    Returns
    Type Description
    Automaton

    DoLookup(string, IEnumerable<BytesRef>, bool, int)

    Look up a key and return possible completion for this key.

    Declaration
    public override IList<Lookup.LookupResult> DoLookup(string key, IEnumerable<BytesRef> contexts, bool onlyMorePopular, int num)
    Parameters
    Type Name Description
    string key

    lookup key. Depending on the implementation this may be a prefix, misspelling, or even infix.

    IEnumerable<BytesRef> 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

    bool onlyMorePopular

    return only more popular results

    int num

    maximum number of results to return

    Returns
    Type Description
    IList<Lookup.LookupResult>

    a list of possible completions, with their relative weight (e.g. popularity)

    Overrides
    Lookup.DoLookup(string, IEnumerable<BytesRef>, bool, int)

    Get(string)

    Returns the weight associated with an input string, or null if it does not exist.

    Declaration
    public virtual object Get(string key)
    Parameters
    Type Name Description
    string key
    Returns
    Type Description
    object

    GetFullPrefixPaths(IList<Path<Pair>>, Automaton, FST<Pair>)

    Returns all prefix paths to initialize the search.

    Declaration
    protected virtual IList<FSTUtil.Path<PairOutputs<Int64, BytesRef>.Pair>> GetFullPrefixPaths(IList<FSTUtil.Path<PairOutputs<Int64, BytesRef>.Pair>> prefixPaths, Automaton lookupAutomaton, FST<PairOutputs<Int64, BytesRef>.Pair> fst)
    Parameters
    Type Name Description
    IList<FSTUtil.Path<PairOutputs<Int64, BytesRef>.Pair>> prefixPaths
    Automaton lookupAutomaton
    FST<PairOutputs<Int64, BytesRef>.Pair> fst
    Returns
    Type Description
    IList<FSTUtil.Path<PairOutputs<Int64, BytesRef>.Pair>>

    GetSizeInBytes()

    Returns byte size of the underlying FST.

    Declaration
    public override long GetSizeInBytes()
    Returns
    Type Description
    long
    Overrides
    Lookup.GetSizeInBytes()

    Load(DataInput)

    Discard current lookup data and load it from a previously saved copy. Optional operation.

    Declaration
    public override bool Load(DataInput input)
    Parameters
    Type Name Description
    DataInput input

    the Lucene.Net.Store.DataInput to load the lookup data.

    Returns
    Type Description
    bool

    true if completed successfully, false if unsuccessful or not supported.

    Overrides
    Lookup.Load(DataInput)
    Exceptions
    Type Condition
    IOException

    when fatal IO error occurs.

    Store(DataOutput)

    Persist the constructed lookup data to a directory. Optional operation.

    Declaration
    public override bool Store(DataOutput output)
    Parameters
    Type Name Description
    DataOutput output

    Lucene.Net.Store.DataOutput to write the data to.

    Returns
    Type Description
    bool

    true if successful, false if unsuccessful or not supported.

    Overrides
    Lookup.Store(DataOutput)
    Exceptions
    Type Condition
    IOException

    when fatal IO error occurs.

    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.