Skip to main content

Session: Querying: How to use Lucene

Lucene flavored syntax can be used with the WhereLucene method, a part of the filtering methods available in IDocumentQuery.

Syntax

IDocumentQuery<T> WhereLucene(string fieldName, string whereClause);
Parameters
fieldNamestringName of a field in an index (default field)
whereClausestringLucene-syntax based clause

Example

List<Company> results = session
.Advanced
.DocumentQuery<Company>()
.WhereLucene("Name", "bistro")
.ToList();

Advanced Usage

The fieldName argument corresponds to Lucene's default field convention. It is mandatory to pass it to the .WhereLucene but the whereClause can contain clause that omits the field entirely giving you the opportunity to pass a complex expression e.g. .WhereLucene("Name", "Name:bistro OR Phone:981-443655"). It is advised to use this approach against Static Index where all fields are known, because there is no guarantee that a proper Auto Index will be created or used.