{NOTE: }
-
This article is about running a full-text search with a dynamic query.
To learn how to run a full-text search using a static-index, see full-text search with index. -
Use the
search()
method to query for documents that contain specified term/s within the text of the specified document field/s. -
When running a full-text search with a dynamic query, the auto-index created by the server breaks down the text of the searched document field using the default search analyzer.
All generated terms are lower-cased, so the search is case-insensitive. -
Gain additional control over term tokenization by running a full-text search using a static-index, where the used analyzer is configurable.
{INFO: }
-
A boost value can be set for each search to prioritize results. Learn more in boost search results.
-
User experience can be enhanced by requesting text fragments that highlight the searched terms in the results. Learn more in highlight search results. {INFO/}
- In this page:
{NOTE/}
{PANEL: Search for single term}
{NOTE: }
{CODE-TABS} {CODE-TAB:python:Query fts_1@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "University") {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
-
Executing the above query will generate the auto-index
Auto/Employees/BySearch(Notes)
. -
This auto-index will contain the following two index-fields:
-
Notes
Contains terms with the original text from the indexed document field 'Notes'.
Text is lower-cased and Not tokenized. -
search(Notes)
Contains lower-cased terms that were tokenized from the 'Notes' field by the default search analyzer (RavenStandardAnalyzer). Calling thesearch()
method targets these terms to find matching documents.
-
{PANEL/}
{PANEL: Search for multiple terms}
-
You can search for multiple terms in the same field in a single search method.
-
By default, the logical operator between these terms is 'OR'.
-
This behavior can be modified. See section Search operators.
{NOTE: }
Pass terms in a string:
{CODE-TABS} {CODE-TAB:python:Query fts_4@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "University Sales Japanese") {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Search in multiple fields}
-
You can search for terms in different fields by making multiple search calls.
-
By default, the logical operator between consecutive search methods is 'OR'.
-
This behavior can be modified. See section Search options.
{NOTE: }
{CODE-TABS} {CODE-TAB:python:Query fts_9@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where (search(Notes, "French") or search(Title, "President")) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Search in complex object}
-
You can search for terms within a complex object.
-
Any nested text field within the object is searchable.
{NOTE: }
{CODE-TABS} {CODE-TAB:python:Query fts_12@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Companies" where search(Address, "USA London") {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Search operators}
-
By default, the logical operator between multiple terms within the same field in a search call is OR.
-
This can be modified using the
@operator
parameter as follows:
{NOTE: }
AND:
{CODE-TABS} {CODE-TAB:python:Query fts_15@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "College German", and) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{NOTE: }
OR:
{CODE-TABS} {CODE-TAB:python:Query fts_18@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "College German") {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Search options}
Search options allow to:
- Negate a search criteria.
- Specify the logical operator used between consecutive search calls.
{NOTE: }
Negate search:
{CODE-TABS} {CODE-TAB:python:Query fts_23@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Companies" where (exists(Address) and not search(Address, "USA")) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{NOTE: }
Default behavior between search calls:
- By default, the logical operator between consecutive search methods is OR.
{CODE-TABS} {CODE-TAB:python:Query fts_24@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Companies" where Contact.Title == "Owner" and (search(Address.Country, "France") or search(Name, "Markets")) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{NOTE: }
Use options as bit flags:
{CODE-TABS} {CODE-TAB:python:Query fts_32@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "French") and (exists(Title) and not search(Title, "Manager")) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Using wildcards}
-
Wildcards can be used to replace:
- Prefix of a searched term
- Postfix of a searched term
- Both prefix & postfix
-
Note:
-
Searching with a wildcard as the prefix of the term (e.g.
*text
) is not advised as it will cause the server to perform a full index scan. -
Instead, consider using a static-index that indexes the field in reverse order
and then query with a wildcard as the postfix, which is much faster.
-
{NOTE: }
{CODE-TABS} {CODE-TAB:python:Query fts_33@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /} {CODE-TAB-BLOCK:sql:RQL} from "Employees" where search(Notes, "art*") or search(Notes, "*logy") or search(Notes, "mark") {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Syntax}
{CODE:python syntax@ClientApi\Session\Querying\TextSearch\FullTextSearch.py /}
Parameter | Type | Description |
---|---|---|
field_name | str |
Name of the searched field. |
search_terms | str |
A string containing the term or terms (separated by spaces) to search for. |
operator | SearchOperator |
Logical operator to use between multiple terms in the same Search method. Can be: SearchOperator.OR or SearchOperator.AND Default: SearchOperation.OR |
Return Type | Description |
---|---|
DocumentQuery[_T] |
The same object used for the query |
{PANEL/}