SQL Reference > Text Search Functions

Text Search Functions

This page covers functions that can be used to make queries involving a text search.

Text search functions operate on fields that have been tokenized into arrays of strings; you may do so by creating a field mapping using the TOKENIZE function.

Also, the SEARCH function only works in the WHERE clause of a query on a collection. It does not work if the target of a query is a subquery or a JOIN, and it does not work in other parts of the query outside of the WHERE clause.

SEARCH may be combined with other operators and functions in the same WHERE clause.

If you use the SEARCH function, SCORE() becomes available as a function with no arguments, returning the score of the match.

Note that text search is currently an experimental feature. Please send us feedback.

BOOST

BOOST(boost_value, term)

Set the boost value (a positive floating point value) for a specific search term. Unboosted terms have a default boost value of 1.0.

CONTAINS

CONTAINS(field, search_string[, locale])

Add terms to the query that correspond to the given search string, tokenized in the given locale (default: en_US). The terms will be placed in a proximity range.

HAS_TERM

HAS_TERM(field, term_value)

Search term that matches when the specified field contains the specified term value.

PROXIMITY

PROXIMITY(term[, term]*)

Create a proximity range for these terms. These terms will contribute 1 point to the final score, just like other terms in the SEARCH query, but will also contribute a score that depends on the longest consecutive match.

PROXIMITY_BOOST

PROXIMITY_BOOST(boost_value, proximity_range)

Set the proximity range boost value (a positive floating point value) for a specific search proximity range. This affects the range’s specific contribution to the score, not the contributions of the individual terms in the range.

proximity_range must be a proximity range created using either PROXIMITY or CONTAINS.

SEARCH

SEARCH(term[, term]*) [OPTION(match_all=false)]

Return documents that match all of the terms (by default), or at least one of the terms (with OPTION(match_all=false)). The terms are arbitrary SQL boolean expressions, optionally boosted.

The score of the match is the sum of the boost values (default 1) for all terms that matched. For searches that include proximity ranges (see below), each proximity range also adds to the score a value equal to (longest match in the proximity range - 1) / 2 (multiplied by the range’s boost value).

TOKENIZE

TOKENIZE(text[, locale])

Tokenize text, interpreted as text in the language specified by locale. locale is specified using the ICU format. The default is en_US_POSIX.

Returns an array of strings corresponding to the words in the text, normalized and lower-cased.