The id type of the documents being indexed.
The type of the documents being indexed.
The type of the documents being indexed.
Search Index
Search query
Search options. Each option, if not given, defaults to the corresponding value of searchOptions
given to the constructor, or to the library default.
Search for documents matching the given search query.
The result is a list of scored document IDs matching the query, sorted by descending score, and each including data about which terms were matched and in which fields.
Basic usage:
Restrict search to specific fields:
Field boosting:
Prefix search:
Fuzzy search:
Combining strategies:
Advanced prefix and fuzzy search:
Combine with AND:
Combine with AND_NOT:
There is also an AND_NOT combinator, that finds documents that match the first term, but do not match any of the other terms. This combinator is rarely useful with simple queries, and is meant to be used with advanced query combinations (see later for more details).
Filtering results:
Wildcard query
Searching for an empty string (assuming the default tokenizer) returns no results. Sometimes though, one needs to match all documents, like in a "wildcard" search. This is possible by passing the special value
wildcard
as the query:Note that search options such as
filter
andboostDocument
are still applied, influencing which results are returned, and their order:Advanced combination of queries:
It is possible to combine different subqueries with OR, AND, and AND_NOT, and even with different search options, by passing a query expression tree object as the first argument, instead of a string.
Each node in the expression tree can be either a string, or an object that supports all
SearchOptions
fields, plus aqueries
array field for subqueries.Note that, while this can become complicated to do by hand for complex or deeply nested queries, it provides a formalized expression tree API for external libraries that implement a parser for custom query languages.