OfficeTextIndex
OfficeIMO.TextAnalysis
In-memory inverted index with positional postings, ranked by BM25F: term, phrase, prefix and AND/OR queries with optional per-field weights, highlights and snippets.
Inheritance
- object
- OfficeTextIndex
Remarks
For a single-term clause t and document d the score is idf(t) · tf' · (k1 + 1) / (tf' + k1), where tf' = Σ_fields weight(f) · tf(t, d, f) / (1 − b + b · length(d, f) / averageLength(f)) and idf(t) = ln(1 + (N − df(t) + 0.5) / (df(t) + 0.5)). With one field of weight 1 this is classic BM25. Field length is its token count; the average is over all documents. A phrase uses its occurrence count as tf and the sum of its terms' idf. A prefix scores as the sum of the terms it expands to. AND and OR add the scores of their matching clauses. Hits are ordered by descending score and then by insertion order, so equal scores rank deterministically. Adding documents is not thread-safe; concurrent searches are safe once no documents are being added.
Constructors
public OfficeTextIndex(OfficeTextIndexOptions? options = null) #Creates an empty index. The options are copied.
Parameters
- options OfficeIMO.TextAnalysis.OfficeTextIndexOptions? = null
Methods
public bool Add(string id, string text) #Indexes one document with one field named body.
Parameters
- id string
- text string
Returns
boolpublic bool Add(string id, params OfficeTextField[] fields) #Indexes one document. Returns false, and sets OfficeTextIndex.LimitReached, when the document was rejected because a limit was already reached. A document that reaches the token limit is indexed up to it and returns true.
Parameters
- id string
- fields OfficeIMO.TextAnalysis.OfficeTextField[]
Returns
boolpublic OfficeTextSnippet? CreateSnippet(OfficeTextIndexHit hit, string field, int maximumCharacters = 280) #Returns up to maximumCharacters of field from the hit's document, centred on its first highlight in that field, or the field start when it has none. Returns null when the document has no such field.
Parameters
- hit OfficeIMO.TextAnalysis.OfficeTextIndexHit
- field string
- maximumCharacters int = 280
Returns
OfficeTextSnippet?public OfficeTextIndexSearchResult Search(string query, OfficeTextIndexSearchOptions options) #Parses query with OfficeTextQuery.Parse, using OfficeTextIndexSearchOptions.DefaultOperator, and searches.
Parameters
- query string
- options OfficeIMO.TextAnalysis.OfficeTextIndexSearchOptions
Returns
OfficeTextIndexSearchResultpublic OfficeTextIndexSearchResult Search(string query) #Parses and searches query with default search options.
Parameters
- query string
Returns
OfficeTextIndexSearchResultpublic OfficeTextIndexSearchResult Search(OfficeTextQuery query) #Evaluates query with default search options.
Parameters
- query OfficeIMO.TextAnalysis.OfficeTextQuery
Returns
OfficeTextIndexSearchResultpublic OfficeTextIndexSearchResult Search(OfficeTextQuery query, OfficeTextIndexSearchOptions options) #Evaluates query and returns ranked hits.
Parameters
- query OfficeIMO.TextAnalysis.OfficeTextQuery
- options OfficeIMO.TextAnalysis.OfficeTextIndexSearchOptions
Returns
OfficeTextIndexSearchResult