Exact Match Query
-
By default, when making a query that filters by strings, the string comparisons are case-insensitive.
-
Use the
exact
parameter to perform a search that is case-sensitive. -
When making a dynamic query with an exact match,
the auto-index created by the server indexes the text of the document field
using the default exact analyzer where the casing of the original text is not changed. -
In this page:
Query with exact match
List<Employee> employees = session
// Make a dynamic query on 'Employees' collection
.Query<Employee>()
// Query for all documents where 'FirstName' equals 'Robert'
// Pass 'exact: true' for a case-sensitive match
.Where(x => x.FirstName == "Robert", exact: true)
.ToList();
List<Employee> employees = await asyncSession
// Make a dynamic query on 'Employees' collection
.Query<Employee>()
// Query for all documents where 'FirstName' equals 'Robert'
// Pass 'exact: true' for a case-sensitive match
.Where(x => x.FirstName == "Robert", exact: true)
.ToListAsync();
List<Employee> employees = session.Advanced
// Make a dynamic DocumentQuery on 'Employees' collection
.DocumentQuery<Employee>()
// Query for all documents where 'FirstName' equals 'Robert'
// Pass 'exact: true' for a case-sensitive match
.WhereEquals(x => x.FirstName, "Robert", exact: true)
.ToList();
from "Employees"
where exact(FirstName == "Robert")
-
Executing the above query will generate the auto-index
Auto/Employees/ByExact(FirstName)
. -
This auto-index will contain the following two index-fields:
-
FirstName
Contains terms with the text from the indexed document field 'FirstName'.
Text is lower-cased and not tokenized. -
exact(FirstName)
Contain terms with the original text from the indexed document field 'FirstName'.
Casing is exactly the same as in the original text, and the text is not tokenized.
Making an exact query targets these terms to find matching documents.
-
Query with exact match - nested object
List<Order> orders = session
// Make a dynamic query on 'Orders' collection
.Query<Order>()
// Query for documents that contain at least one order line with 'Teatime Chocolate Biscuits'
.Where(x => x.Lines.Any(p => p.ProductName == "Teatime Chocolate Biscuits"),
// Pass 'exact: true' for a case-sensitive match
exact: true)
.ToList();
List<Order> orders = await asyncSession
// Make a dynamic query on 'Orders' collection
.Query<Order>()
// Query for documents that contain at least one order line with 'Teatime Chocolate Biscuits'
.Where(x => x.Lines.Any(p => p.ProductName == "Teatime Chocolate Biscuits"),
// Pass 'exact: true' for a case-sensitive match
exact: true)
.ToListAsync();
List<Order> orders = session.Advanced
// Make a dynamic DocumentQuery on 'Orders' collection
.DocumentQuery<Order>()
// Query for documents that contain at least one order line with 'Teatime Chocolate Biscuits'
.WhereEquals("Lines.ProductName", "Teatime Chocolate Biscuits",
// Pass 'exact: true' for a case-sensitive match
exact: true)
.ToList();
from "Orders"
where exact(Lines.ProductName == "Teatime Chocolate Biscuits")
Syntax
IRavenQueryable<T> Where<T>(Expression<Func<T, bool>> predicate, bool exact);
Parameter | Type | Description |
---|---|---|
predicate | Expression<Func<T, bool>> | Predicate with match condition |
exact | bool | false - search is case-insensitivetrue - search is case-sensitive |