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 | ||
---|---|---|
fieldName | String | Name of a field in an index (default field) |
whereClause | String | Lucene-syntax based clause |
Example
session
.advanced()
.documentQuery(Company.class)
.whereLucene("Name", "bistro")
.toList();
from Companies
where lucene(Name, 'bistro')
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.