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
    Implements
    System.IDisposable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Lucene.Net.Search.Spell
    Assembly: Lucene.Net.Suggest.dll
    Syntax
    public class SpellChecker : IDisposable

    Constructors

    | Improve this Doc View Source

    SpellChecker(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(Directory spellIndex)
    Parameters
    Type Name Description
    Directory spellIndex

    the spell index directory

    Exceptions
    Type Condition
    System.IO.IOException

    if spellchecker can not open the directory

    | Improve this Doc View Source

    SpellChecker(Directory, IStringDistance)

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

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

    the spell index directory

    IStringDistance sd

    the StringDistance measurement to use

    Exceptions
    Type Condition
    System.IO.IOException

    if Spellchecker can not open the directory

    | Improve this Doc View Source

    SpellChecker(Directory, IStringDistance, IComparer<SuggestWord>)

    Use the given directory as a spell checker index with the given IStringDistance measure and the given System.Collections.Generic.IComparer<T> for sorting the results.

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

    The spelling index

    IStringDistance sd

    The distance

    System.Collections.Generic.IComparer<SuggestWord> comparer

    The comparer

    Exceptions
    Type Condition
    System.IO.IOException

    if there is a problem opening the index

    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 = 0.5F
    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 = "word"
    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 System.Collections.Generic.IComparer<T> for the SuggestWordQueue.

    Declaration
    public virtual IComparer<SuggestWord> Comparer { get; set; }
    Property Value
    Type Description
    System.Collections.Generic.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()
    Exceptions
    Type Condition
    System.IO.IOException

    If there is a low-level I/O error.

    System.ObjectDisposedException

    if the Spellchecker is already closed

    | Improve this Doc View Source

    Dispose()

    Dispose the underlying IndexSearcher used by this SpellChecker

    Declaration
    public void Dispose()
    Exceptions
    Type Condition
    System.IO.IOException

    if the close operation causes an System.IO.IOException

    System.ObjectDisposedException

    if the SpellChecker is already disposed

    | 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

    Exceptions
    Type Condition
    System.IO.IOException

    If there is a low-level I/O error.

    System.ObjectDisposedException

    if the SpellChecker is already disposed

    | 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

    IndexWriterConfig to use

    System.Boolean fullMerge

    whether or not the spellcheck index should be fully merged

    Exceptions
    Type Condition
    System.ObjectDisposedException

    if the SpellChecker is already disposed

    System.IO.IOException

    If there is a low-level I/O error.

    | Improve this Doc View Source

    SetSpellIndex(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(Directory spellIndexDir)
    Parameters
    Type Name Description
    Directory spellIndexDir

    the spell directory to use

    Exceptions
    Type Condition
    System.ObjectDisposedException

    if the Spellchecker is already closed

    System.IO.IOException

    if spellchecker can not open the directory

    | 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

    Exceptions
    Type Condition
    System.IO.IOException

    if the underlying index throws an System.IO.IOException

    System.ObjectDisposedException

    if the Spellchecker is already disposed

    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

    Exceptions
    Type Condition
    System.IO.IOException

    if the underlying index throws an System.IO.IOException

    System.ObjectDisposedException

    if the SpellChecker is already disposed

    | 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

    Exceptions
    Type Condition
    System.IO.IOException

    if the underlying index throws an System.IO.IOException

    System.ObjectDisposedException

    if the Spellchecker is already disposed

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

    Implements

    System.IDisposable
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)