Class AnalyzingInfixSuggester
Analyzes the input text and then suggests matches based on prefix matches to any tokens in the indexed text. This also highlights the tokens that match.
This suggester supports payloads. Matches are sorted only by the suggest weight; it would be nice to support blended score + weight sort in the future. This means this suggester best applies when there is a strong a-priori ranking of all the suggestions.
This suggester supports contexts, however the contexts must be valid utf8 (arbitrary binary terms will not work).
Note
This API is experimental and might change in incompatible ways in the next release.
Implements
Inherited Members
Namespace: Lucene.Net.Search.Suggest.Analyzing
Assembly: Lucene.Net.Suggest.dll
Syntax
public class AnalyzingInfixSuggester : Lookup, IDisposable
Constructors
AnalyzingInfixSuggester(IAnalyzingInfixSuggesterIndexWriterConfigFactory, LuceneVersion, Directory, Analyzer, Analyzer, int, bool)
Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that Dispose() will also dispose the provided directory.
Declaration
public AnalyzingInfixSuggester(IAnalyzingInfixSuggesterIndexWriterConfigFactory indexWriterConfigFactory, LuceneVersion matchVersion, Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, bool commitOnBuild)
Parameters
Type | Name | Description |
---|---|---|
IAnalyzingInfixSuggesterIndexWriterConfigFactory | indexWriterConfigFactory | Factory for creating the Lucene.Net.Index.IndexWriterConfig. |
LuceneVersion | matchVersion | |
Directory | dir | |
Analyzer | indexAnalyzer | |
Analyzer | queryAnalyzer | |
int | minPrefixChars | Minimum number of leading characters before Lucene.Net.Search.PrefixQuery is used (default 4). Prefixes shorter than this are indexed as character ngrams (increasing index size but making lookups faster). |
bool | 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. |
AnalyzingInfixSuggester(LuceneVersion, Directory, Analyzer)
Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that Dispose() will also dispose the provided directory.
Declaration
public AnalyzingInfixSuggester(LuceneVersion matchVersion, Directory dir, Analyzer analyzer)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | |
Directory | dir | |
Analyzer | analyzer |
AnalyzingInfixSuggester(LuceneVersion, Directory, Analyzer, Analyzer, int)
Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that Dispose() will also dispose the provided directory.
Declaration
public AnalyzingInfixSuggester(LuceneVersion matchVersion, Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | |
Directory | dir | |
Analyzer | indexAnalyzer | |
Analyzer | queryAnalyzer | |
int | minPrefixChars | Minimum number of leading characters before Lucene.Net.Search.PrefixQuery is used (default 4). Prefixes shorter than this are indexed as character ngrams (increasing index size but making lookups faster). |
AnalyzingInfixSuggester(LuceneVersion, Directory, Analyzer, Analyzer, int, bool)
Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that Dispose() will also dispose the provided directory.
Declaration
public AnalyzingInfixSuggester(LuceneVersion matchVersion, Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, bool commitOnBuild)
Parameters
Type | Name | Description |
---|---|---|
LuceneVersion | matchVersion | |
Directory | dir | |
Analyzer | indexAnalyzer | |
Analyzer | queryAnalyzer | |
int | minPrefixChars | Minimum number of leading characters before Lucene.Net.Search.PrefixQuery is used (default 4). Prefixes shorter than this are indexed as character ngrams (increasing index size but making lookups faster). |
bool | 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. |
Fields
CONTEXTS_FIELD_NAME
Field name used for the indexed context, as a Lucene.Net.Documents.StringField and a Lucene.Net.Documents.SortedSetDocValuesField, for filtering.
Declaration
protected const string CONTEXTS_FIELD_NAME = "contexts"
Field Value
Type | Description |
---|---|
string |
DEFAULT_MIN_PREFIX_CHARS
Default minimum number of leading characters before PrefixQuery is used (4).
Declaration
public const int DEFAULT_MIN_PREFIX_CHARS = 4
Field Value
Type | Description |
---|---|
int |
EXACT_TEXT_FIELD_NAME
Field name used for the indexed text, as a Lucene.Net.Documents.StringField, for exact lookup.
Declaration
protected const string EXACT_TEXT_FIELD_NAME = "exacttext"
Field Value
Type | Description |
---|---|
string |
TEXT_FIELD_NAME
Field name used for the indexed text.
Declaration
protected const string TEXT_FIELD_NAME = "text"
Field Value
Type | Description |
---|---|
string |
m_indexAnalyzer
Analyzer used at index time
Declaration
protected readonly Analyzer m_indexAnalyzer
Field Value
Type | Description |
---|---|
Analyzer |
m_queryAnalyzer
Analyzer used at search time
Declaration
protected readonly Analyzer m_queryAnalyzer
Field Value
Type | Description |
---|---|
Analyzer |
m_searcherMgr
Lucene.Net.Search.IndexSearcher used for lookups.
Declaration
protected SearcherManager m_searcherMgr
Field Value
Type | Description |
---|---|
SearcherManager |
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
Methods
Add(BytesRef, IEnumerable<BytesRef>, long, BytesRef)
Adds a new suggestion. Be sure to use Update(BytesRef, IEnumerable<BytesRef>, long, BytesRef) instead if you want to replace a previous suggestion. After adding or updating a batch of new suggestions, you must call Refresh() in the end in order to see the suggestions in DoLookup(string, IEnumerable<BytesRef>, int, bool, bool)
Declaration
public virtual void Add(BytesRef text, IEnumerable<BytesRef> contexts, long weight, BytesRef payload)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | text | |
IEnumerable<BytesRef> | contexts | |
long | weight | |
BytesRef | payload |
AddNonMatch(StringBuilder, string)
Called while highlighting a single result, to append a non-matching chunk of text from the suggestion to the provided fragments list.
Declaration
protected virtual void AddNonMatch(StringBuilder sb, string text)
Parameters
Type | Name | Description |
---|---|---|
StringBuilder | sb | The StringBuilder to append to |
string | text | The text chunk to add |
AddPrefixMatch(StringBuilder, string, string, string)
Called while highlighting a single result, to append a matched prefix token, to the provided fragments list.
Declaration
protected virtual void AddPrefixMatch(StringBuilder sb, string surface, string analyzed, string prefixToken)
Parameters
Type | Name | Description |
---|---|---|
StringBuilder | sb | The StringBuilder to append to |
string | surface | The fragment of the surface form (indexed during Build(IInputEnumerator), corresponding to this match |
string | analyzed | The analyzed token that matched |
string | prefixToken | The prefix of the token that matched |
AddWholeMatch(StringBuilder, string, string)
Called while highlighting a single result, to append the whole matched token to the provided fragments list.
Declaration
protected virtual void AddWholeMatch(StringBuilder sb, string surface, string analyzed)
Parameters
Type | Name | Description |
---|---|---|
StringBuilder | sb | The StringBuilder to append to |
string | surface | The surface form (original) text |
string | analyzed | The analyzed token corresponding to the surface form text |
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
Commit()
Analyzes the input text and then suggests matches based on prefix matches to any tokens in the indexed text. This also highlights the tokens that match.
This suggester supports payloads. Matches are sorted only by the suggest weight; it would be nice to support blended score + weight sort in the future. This means this suggester best applies when there is a strong a-priori ranking of all the suggestions.
This suggester supports contexts, however the contexts must be valid utf8 (arbitrary binary terms will not work).
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
public void Commit()
CreateResults(IndexSearcher, TopFieldDocs, int, string, bool, ICollection<string>, string)
Create the results based on the search hits. Can be overridden by subclass to add particular behavior (e.g. weight transformation)
Declaration
protected virtual IList<Lookup.LookupResult> CreateResults(IndexSearcher searcher, TopFieldDocs hits, int num, string charSequence, bool doHighlight, ICollection<string> matchedTokens, string prefixToken)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | searcher | |
TopFieldDocs | hits | |
int | num | |
string | charSequence | |
bool | doHighlight | |
ICollection<string> | matchedTokens | |
string | prefixToken |
Returns
Type | Description |
---|---|
IList<Lookup.LookupResult> |
Exceptions
Type | Condition |
---|---|
IOException | If there are problems reading fields from the underlying Lucene index. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Analyzes the input text and then suggests matches based on prefix matches to any tokens in the indexed text. This also highlights the tokens that match.
This suggester supports payloads. Matches are sorted only by the suggest weight; it would be nice to support blended score + weight sort in the future. This means this suggester best applies when there is a strong a-priori ranking of all the suggestions.
This suggester supports contexts, however the contexts must be valid utf8 (arbitrary binary terms will not work).
Note
This API is experimental and might change in incompatible ways in the next release.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
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
DoLookup(string, IEnumerable<BytesRef>, int, bool, bool)
Retrieve suggestions, specifying whether all terms
must match (allTermsRequired
) and whether the hits
should be highlighted (doHighlight
).
Declaration
public virtual IList<Lookup.LookupResult> DoLookup(string key, IEnumerable<BytesRef> contexts, int num, bool allTermsRequired, bool doHighlight)
Parameters
Type | Name | Description |
---|---|---|
string | key | |
IEnumerable<BytesRef> | contexts | |
int | num | |
bool | allTermsRequired | |
bool | doHighlight |
Returns
Type | Description |
---|---|
IList<Lookup.LookupResult> |
DoLookup(string, int, bool, bool)
Lookup, without any context.
Declaration
public virtual IList<Lookup.LookupResult> DoLookup(string key, int num, bool allTermsRequired, bool doHighlight)
Parameters
Type | Name | Description |
---|---|---|
string | key | |
int | num | |
bool | allTermsRequired | |
bool | doHighlight |
Returns
Type | Description |
---|---|
IList<Lookup.LookupResult> |
FinishQuery(BooleanQuery, bool)
Subclass can override this to tweak the Query before searching.
Declaration
protected virtual Query FinishQuery(BooleanQuery bq, bool allTermsRequired)
Parameters
Type | Name | Description |
---|---|---|
BooleanQuery | bq | |
bool | allTermsRequired |
Returns
Type | Description |
---|---|
Query |
GetDirectory(DirectoryInfo)
Subclass can override to choose a specific Lucene.Net.Store.Directory implementation.
Declaration
protected virtual Directory GetDirectory(DirectoryInfo path)
Parameters
Type | Name | Description |
---|---|---|
DirectoryInfo | path |
Returns
Type | Description |
---|---|
Directory |
GetLastTokenQuery(string)
This is called if the last token isn't ended (e.g. user did not type a space after it). Return an appropriate Lucene.Net.Search.Query clause to add to the Lucene.Net.Search.BooleanQuery.
Declaration
protected virtual Query GetLastTokenQuery(string token)
Parameters
Type | Name | Description |
---|---|---|
string | token |
Returns
Type | Description |
---|---|
Query |
GetSizeInBytes()
Get the size of the underlying lookup implementation in memory
Declaration
public override long GetSizeInBytes()
Returns
Type | Description |
---|---|
long | ram size of the lookup implementation in bytes |
Overrides
GetTextFieldType()
Subclass can override this method to change the field type of the text field e.g. to change the index options
Declaration
protected virtual FieldType GetTextFieldType()
Returns
Type | Description |
---|---|
FieldType |
Highlight(string, ICollection<string>, string)
Override this method to customize the Object representing a single highlighted suggestions; the result is set on each HighlightKey member.
Declaration
protected virtual object Highlight(string text, ICollection<string> matchedTokens, string prefixToken)
Parameters
Type | Name | Description |
---|---|---|
string | text | |
ICollection<string> | matchedTokens | |
string | prefixToken |
Returns
Type | Description |
---|---|
object |
Load(DataInput)
Discard current lookup data and load it from a previously saved copy. Optional operation.
Declaration
public override bool Load(DataInput @out)
Parameters
Type | Name | Description |
---|---|---|
DataInput | out |
Returns
Type | Description |
---|---|
bool | true if completed successfully, false if unsuccessful or not supported. |
Overrides
Exceptions
Type | Condition |
---|---|
IOException | when fatal IO error occurs. |
Refresh()
Reopens the underlying searcher; it's best to "batch up" many additions/updates, and then call refresh once in the end.
Declaration
public virtual void Refresh()
Store(DataOutput)
Persist the constructed lookup data to a directory. Optional operation.
Declaration
public override bool Store(DataOutput @in)
Parameters
Type | Name | Description |
---|---|---|
DataOutput | in |
Returns
Type | Description |
---|---|
bool | true if successful, false if unsuccessful or not supported. |
Overrides
Exceptions
Type | Condition |
---|---|
IOException | when fatal IO error occurs. |
Update(BytesRef, IEnumerable<BytesRef>, long, BytesRef)
Updates a previous suggestion, matching the exact same text as before. Use this to change the weight or payload of an already added suggstion. If you know this text is not already present you can use Add(BytesRef, IEnumerable<BytesRef>, long, BytesRef) instead. After adding or updating a batch of new suggestions, you must call Refresh() in the end in order to see the suggestions in DoLookup(string, IEnumerable<BytesRef>, int, bool, bool)
Declaration
public virtual void Update(BytesRef text, IEnumerable<BytesRef> contexts, long weight, BytesRef payload)
Parameters
Type | Name | Description |
---|---|---|
BytesRef | text | |
IEnumerable<BytesRef> | contexts | |
long | weight | |
BytesRef | payload |