C# Class SpellChecker.Net.Search.Spell.SpellChecker

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

Example Usage:

 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 File("myfile.txt"))); String[] suggestions = spellchecker.suggestSimilar("misspelt", 5); 
Exibir arquivo Open project: synhershko/lucene.net Class Usage Examples

Public Methods

Method Description
ClearIndex ( ) : void

Removes all terms from the spell check index.

Close ( ) : void
CreateSearcher ( Lucene.Net.Store.Directory dir ) : IndexSearcher

Creates a new read-only IndexSearcher (for testing purposes)

Dispose ( ) : void
Exist ( System word ) : bool

Check whether the word exists in the index.

GetStringDistance ( ) : StringDistance

Returns the StringDistance instance used by this SpellChecker instance.

IndexDictionary ( IDictionary dict ) : void

Indexes the data from the given IDictionary.

IndexDictionary ( IDictionary dict, int mergeFactor, int ramMB ) : void

Index a Dictionary

SetAccuracy ( float minScore ) : void

Set the accuracy 0 < min < 1; default 0.5

SetSpellIndex ( Lucene.Net.Store.Directory spellIndexDir ) : void

Use 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.

SpellChecker ( Lucene.Net.Store.Directory spellIndex ) : System

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

SpellChecker ( Lucene.Net.Store.Directory spellIndex, StringDistance sd ) : System

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

SuggestSimilar ( System word, int num_sug ) : System.String[]

Suggest similar words

SuggestSimilar ( System word, int numSug, Lucene.Net.Index.IndexReader ir, System field, bool morePopular ) : System.String[]

Suggest similar words (restricted or not to a field of a user index)

setStringDistance ( StringDistance sd ) : void

Sets the StringDistance implementation for this SpellChecker instance.

Protected Methods

Method Description
Dispose ( bool disposeOfManagedResources ) : void

Private Methods

Method Description
Add ( Lucene.Net.Search.BooleanQuery q, System k, System v ) : void

Add a clause to a boolean query.

Add ( Lucene.Net.Search.BooleanQuery q, System k, System v, float boost ) : void

Add a clause to a boolean query.

AddGram ( System text, Lucene.Net.Documents.Document doc, int ng1, int ng2 ) : void
CreateDocument ( System text, int ng1, int ng2 ) : Lucene.Net.Documents.Document
EnsureOpen ( ) : void
FormGrams ( System text, int ng ) : System.String[]

Form all ngrams for a given word.

GetMax ( int l ) : int
GetMin ( int l ) : int
IsClosed ( ) : bool

Returns true if and only if the SpellChecker is closed, otherwise false.

ObtainSearcher ( ) : IndexSearcher
ReleaseSearcher ( IndexSearcher aSearcher ) : void
SwapSearcher ( Lucene.Net.Store.Directory dir ) : void

Method Details

ClearIndex() public method

Removes all terms from the spell check index.
public ClearIndex ( ) : void
return void

Close() public method

public Close ( ) : void
return void

CreateSearcher() public method

Creates a new read-only IndexSearcher (for testing purposes)
public CreateSearcher ( Lucene.Net.Store.Directory dir ) : IndexSearcher
dir Lucene.Net.Store.Directory dir the directory used to open the searcher
return Lucene.Net.Search.IndexSearcher

Dispose() public method

public Dispose ( ) : void
return void

Dispose() protected method

protected Dispose ( bool disposeOfManagedResources ) : void
disposeOfManagedResources bool
return void

Exist() public method

Check whether the word exists in the index.
public Exist ( System word ) : bool
word System String ///
return bool

GetStringDistance() public method

Returns the StringDistance instance used by this SpellChecker instance.
public GetStringDistance ( ) : StringDistance
return StringDistance

IndexDictionary() public method

Indexes the data from the given IDictionary.
public IndexDictionary ( IDictionary dict ) : void
dict IDictionary dict the dictionary to index
return void

IndexDictionary() public method

Index a Dictionary
public IndexDictionary ( IDictionary dict, int mergeFactor, int ramMB ) : void
dict IDictionary the dictionary to index
mergeFactor int mergeFactor to use when indexing
ramMB int the max amount or memory in MB to use
return void

SetAccuracy() public method

Set the accuracy 0 < min < 1; default 0.5
public SetAccuracy ( float minScore ) : void
minScore float
return void

SetSpellIndex() public method

Use 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.
public SetSpellIndex ( Lucene.Net.Store.Directory spellIndexDir ) : void
spellIndexDir Lucene.Net.Store.Directory spellIndexDir the spell directory to use
return void

SpellChecker() public method

Use the given directory as a spell checker index with a LevenshteinDistance as the default StringDistance. The directory is created if it doesn't exist yet.
public SpellChecker ( Lucene.Net.Store.Directory spellIndex ) : System
spellIndex Lucene.Net.Store.Directory the spell index directory
return System

SpellChecker() public method

Use the given directory as a spell checker index. The directory is created if it doesn't exist yet.
public SpellChecker ( Lucene.Net.Store.Directory spellIndex, StringDistance sd ) : System
spellIndex Lucene.Net.Store.Directory the spell index directory
sd StringDistance the measurement to use
return System

SuggestSimilar() public method

Suggest similar words
public SuggestSimilar ( System word, int num_sug ) : System.String[]
word System String the word you want a spell check done on ///
num_sug int int the number of suggest words ///
return System.String[]

SuggestSimilar() public method

Suggest similar words (restricted or not to a field of a user index)
public SuggestSimilar ( System word, int numSug, Lucene.Net.Index.IndexReader ir, System field, bool morePopular ) : System.String[]
word System String the word you want a spell check done on ///
numSug int int the number of suggest words ///
ir Lucene.Net.Index.IndexReader the indexReader of the user index (can be null see field param) ///
field System String the field of the user index: if field is not null, the suggested /// words are restricted to the words present in this field. ///
morePopular bool boolean return only the suggest words that are more frequent than the searched word /// (only if restricted mode = (indexReader!=null and field!=null) ///
return System.String[]

setStringDistance() public method

Sets the StringDistance implementation for this SpellChecker instance.
public setStringDistance ( StringDistance sd ) : void
sd StringDistance the implementation for this /// instance.
return void