Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

OfficeTextIndex

OfficeIMO.TextAnalysis

Namespace
OfficeIMO.TextAnalysis
Assembly
OfficeIMO.Core
Source revision
ac7e6e1bad8a with working tree changes
Modifiers
sealed

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 optional

Methods

Add 2 overloads
public bool Add(string id, string text) #

Indexes one document with one field named body.

Parameters

id string required
text string required

Returns

bool
public 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 required
fields OfficeIMO.TextAnalysis.OfficeTextField[] required

Returns

bool
public 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 required
field string required
maximumCharacters int = 280 optional
Search 4 overloads
public OfficeTextIndexSearchResult Search(string query, OfficeTextIndexSearchOptions options) #

Parses query with OfficeTextQuery.Parse, using OfficeTextIndexSearchOptions.DefaultOperator, and searches.

Parameters

query string required
options OfficeIMO.TextAnalysis.OfficeTextIndexSearchOptions required
public OfficeTextIndexSearchResult Search(string query) #

Parses and searches query with default search options.

Parameters

query string required
public OfficeTextIndexSearchResult Search(OfficeTextQuery query) #

Evaluates query with default search options.

Parameters

query OfficeIMO.TextAnalysis.OfficeTextQuery required
public OfficeTextIndexSearchResult Search(OfficeTextQuery query, OfficeTextIndexSearchOptions options) #

Evaluates query and returns ranked hits.

Parameters

query OfficeIMO.TextAnalysis.OfficeTextQuery required
options OfficeIMO.TextAnalysis.OfficeTextIndexSearchOptions required

Properties

public OfficeTextAnalyzer Analyzer { get; } #

Analyser used for indexed and query text.

public int DocumentCount { get; } #

Number of indexed documents.

public int TermCount { get; } #

Number of distinct terms.

public long TokenCount { get; } #

Number of tokens held by the index.

public bool LimitReached { get; private set; } #

True when a document or token limit truncated or rejected input.