How to search against a LIFTI index

There are two ways to query a FullTextIndex, searching with a query string and executing a manually constructed Query.

Searching with text

index.Search("find something");

This approach uses the IQueryParser implementation configured for the index to parse the query text into a Query object, which is then executed.

The default IQueryParser that is configured against an index parses the LIFTI query syntax, which is a fairly flexible way of expressing a query. If you want to swap out this parser with a custom implementation, you can do so when building the index using WithQueryParser option.

Searching with a Query

You can manually construct a Query using any combination of IQueryParts, but take care to normalize any text to match in the same way that it has been indexed. You can do this using either the ITokenizer for the index, or if specific tokenization rules have been configured for a field, then the tokenizer for that field:

var tokenizer = index.DefaultTokenizer;
var query = new Query(
    new AndQueryPart(
        new ExactWordQueryPart(tokenizer.Normalize("hello")), 
        new ExactWordQueryPart(tokenizer.Normalize("there"))));

The LIFTI Query Syntax

The LIFTI query syntax

Manually Constructing Query Objects

Instead of using a query parser to interpret your query, you can manually construct a Query object and execute it against the index.


You can use an IndexNavigator to navigate the index character by character.

Search Results

Results from FullTextIndex<T>.Search are an enumeration of SearchResult<T>

Last modified February 12, 2022: Added more querying docs (b704135)