Show / Hide Table of Contents

    Class SpellChecker

    Spell Checker class (Main class)
    (initially inspired by the David Spencer code).

    Example Usage (C#):

     SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
     // To index a field of a user index:
     spellchecker.IndexDictionary(new LuceneDictionary(my_lucene_reader, a_field));
     // To index a file containing words:
     spellchecker.IndexDictionary(new PlainTextDictionary(new FileInfo("myfile.txt")));
     string[] suggestions = spellchecker.SuggestSimilar("misspelt", 5);

    Inheritance
    System.Object
    SpellChecker
    Namespace: Lucene.Net.Search.Spell
    Assembly: Lucene.Net.Suggest.dll
    Syntax
    public class SpellChecker : IDisposable

    Constructors

    | Improve this Doc View Source

    SpellChecker(Store.Directory)

    Use the given directory as a spell checker index with a LevensteinDistance as the default StringDistance. The directory is created if it doesn't exist yet.

    Declaration
    public SpellChecker(Store.Directory spellIndex)
    Parameters
    Type Name Description
    Store.Directory spellIndex

    the spell index directory

    | Improve this Doc View Source

    SpellChecker(Store.Directory, IStringDistance)

    Use the given directory as a spell checker index. The directory is created if it doesn't exist yet.

    Declaration
    public SpellChecker(Store.Directory spellIndex, IStringDistance sd)
    Parameters
    Type Name Description
    Store.Directory spellIndex

    the spell index directory

    IStringDistance sd

    the StringDistance measurement to use

    | Improve this Doc View Source

    SpellChecker(Store.Directory, IStringDistance, IComparer<SuggestWord>)

    Use the given directory as a spell checker index with the given IStringDistance measure and the given for sorting the results.

    Declaration
    public SpellChecker(Store.Directory spellIndex, IStringDistance sd, IComparer<SuggestWord> comparer)
    Parameters
    Type Name Description
    Store.Directory spellIndex

    The spelling index

    IStringDistance sd

    The distance

    IComparer<SuggestWord> comparer

    The comparer

    Fields

    | Improve this Doc View Source

    DEFAULT_ACCURACY

    The default minimum score to use, if not specified by setting Accuracy or overriding with SuggestSimilar(String, Int32, IndexReader, String, SuggestMode, Single) .

    Declaration
    public const float DEFAULT_ACCURACY = null
    Field Value
    Type Description
    System.Single
    | Improve this Doc View Source

    F_WORD

    Field name for each word in the ngram index.

    Declaration
    public const string F_WORD = null
    Field Value
    Type Description
    System.String

    Properties

    | Improve this Doc View Source

    Accuracy

    Gets or sets the accuracy (minimum score) to be used, unless overridden in SuggestSimilar(String, Int32, IndexReader, String, SuggestMode, Single), to decide whether a suggestion is included or not. Sets the accuracy 0 < minScore < 1; default DEFAULT_ACCURACY

    Declaration
    public virtual float Accuracy { get; set; }
    Property Value
    Type Description
    System.Single
    | Improve this Doc View Source

    Comparer

    Gets or sets the for the SuggestWordQueue.

    Declaration
    public virtual IComparer<SuggestWord> Comparer { get; set; }
    Property Value
    Type Description
    IComparer<SuggestWord>
    | Improve this Doc View Source

    StringDistance

    Gets or sets the IStringDistance implementation for this SpellChecker instance.

    Declaration
    public virtual IStringDistance StringDistance { get; set; }
    Property Value
    Type Description
    IStringDistance

    Methods

    | Improve this Doc View Source

    ClearIndex()

    Removes all terms from the spell check index.

    Declaration
    public virtual void ClearIndex()
    | Improve this Doc View Source

    Dispose()

    Dispose the underlying IndexSearcher used by this SpellChecker

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    Exist(String)

    Check whether the word exists in the index.

    Declaration
    public virtual bool Exist(string word)
    Parameters
    Type Name Description
    System.String word

    word to check

    Returns
    Type Description
    System.Boolean

    true if the word exists in the index

    | Improve this Doc View Source

    IndexDictionary(IDictionary, IndexWriterConfig, Boolean)

    Indexes the data from the given IDictionary.

    Declaration
    public void IndexDictionary(IDictionary dict, IndexWriterConfig config, bool fullMerge)
    Parameters
    Type Name Description
    IDictionary dict

    Dictionary to index

    IndexWriterConfig config

    to use

    System.Boolean fullMerge

    whether or not the spellcheck index should be fully merged

    | Improve this Doc View Source

    SetSpellIndex(Store.Directory)

    Sets a different index as the spell checker index or re-open the existing index if

    spellIndex
    is the same value as given in the constructor.

    Declaration
    public virtual void SetSpellIndex(Store.Directory spellIndexDir)
    Parameters
    Type Name Description
    Store.Directory spellIndexDir

    the spell directory to use

    | Improve this Doc View Source

    SuggestSimilar(String, Int32)

    Suggest similar words.

    As the Lucene similarity that is used to fetch the most relevant n-grammed terms is not the same as the edit distance strategy used to calculate the best matching spell-checked word from the hits that Lucene found, one usually has to retrieve a couple of numSug's in order to get the true best match.

    I.e. if numSug == 1, don't count on that suggestion being the best one. Thus, you should set this value to at least 5 for a good suggestion.

    Declaration
    public virtual string[] SuggestSimilar(string word, int numSug)
    Parameters
    Type Name Description
    System.String word

    the word you want a spell check done on

    System.Int32 numSug

    the number of suggested words

    Returns
    Type Description
    System.String[]

    string[] the sorted list of the suggest words with these 2 criteria: first criteria: the edit distance, second criteria (only if restricted mode): the popularity of the suggest words in the field of the user index

    See Also
    SuggestSimilar(String, Int32, IndexReader, String, SuggestMode, Single)
    | Improve this Doc View Source

    SuggestSimilar(String, Int32, IndexReader, String, SuggestMode)

    Calls SuggestSimilar(String, Int32, IndexReader, String, SuggestMode, Single) SuggestSimilar(word, numSug, ir, suggestMode, field, this.accuracy)

    Declaration
    public virtual string[] SuggestSimilar(string word, int numSug, IndexReader ir, string field, SuggestMode suggestMode)
    Parameters
    Type Name Description
    System.String word
    System.Int32 numSug
    IndexReader ir
    System.String field
    SuggestMode suggestMode
    Returns
    Type Description
    System.String[]
    | Improve this Doc View Source

    SuggestSimilar(String, Int32, IndexReader, String, SuggestMode, Single)

    Suggest similar words (optionally restricted to a field of an index).

    As the Lucene similarity that is used to fetch the most relevant n-grammed terms is not the same as the edit distance strategy used to calculate the best matching spell-checked word from the hits that Lucene found, one usually has to retrieve a couple of numSug's in order to get the true best match.

    I.e. if numSug == 1, don't count on that suggestion being the best one. Thus, you should set this value to at least 5 for a good suggestion.

    Declaration
    public virtual string[] SuggestSimilar(string word, int numSug, IndexReader ir, string field, SuggestMode suggestMode, float accuracy)
    Parameters
    Type Name Description
    System.String word

    the word you want a spell check done on

    System.Int32 numSug

    the number of suggested words

    IndexReader ir

    the indexReader of the user index (can be null see field param)

    System.String field

    the field of the user index: if field is not null, the suggested words are restricted to the words present in this field.

    SuggestMode suggestMode

    (NOTE: if indexReader==null and/or field==null, then this is overridden with SuggestMode.SUGGEST_ALWAYS)

    System.Single accuracy

    The minimum score a suggestion must have in order to qualify for inclusion in the results

    Returns
    Type Description
    System.String[]

    string[] the sorted list of the suggest words with these 2 criteria: first criteria: the edit distance, second criteria (only if restricted mode): the popularity of the suggest words in the field of the user index

    | Improve this Doc View Source

    SuggestSimilar(String, Int32, Single)

    Suggest similar words.

    As the Lucene similarity that is used to fetch the most relevant n-grammed terms is not the same as the edit distance strategy used to calculate the best matching spell-checked word from the hits that Lucene found, one usually has to retrieve a couple of numSug's in order to get the true best match.

    I.e. if numSug == 1, don't count on that suggestion being the best one. Thus, you should set this value to at least 5 for a good suggestion.

    Declaration
    public virtual string[] SuggestSimilar(string word, int numSug, float accuracy)
    Parameters
    Type Name Description
    System.String word

    the word you want a spell check done on

    System.Int32 numSug

    the number of suggested words

    System.Single accuracy

    The minimum score a suggestion must have in order to qualify for inclusion in the results

    Returns
    Type Description
    System.String[]

    string[] the sorted list of the suggest words with these 2 criteria: first criteria: the edit distance, second criteria (only if restricted mode): the popularity of the suggest words in the field of the user index

    See Also
    SuggestSimilar(String, Int32, IndexReader, String, SuggestMode, Single)
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)