Skip to main content
Proximity queries are used to match documents containing tokens that are within a certain token distance of one another.

Overview

The following query finds all documents where the token sleek is at most 1 token away from shoes.
Like the term query, the query string in a proximity query is treated as a finalized token.
## does not care about order — the term on the left-hand side may appear before or after the term on the right-hand side. To ensure that the left-hand term appears before the right-hand term, use ##>.

Proximity Regex

In addition to exact tokens, proximity queries can also match against regex expressions. The following query finds all documents where any token matching the regex query sl.* is at most 1 token away from the token shoes.
By default, pdb.prox_regex will expand to the first 50 regex matches in each document. This limit can be overridden by providing a second argument:

Proximity Array

pdb.prox_array matches against an array of tokens instead of a single token. For example, the following query finds all documents where any of the tokens sleek or white is within 1 token of shoes.
pdb.prox_array can also take regex:

Proximity Chaining

Multiple proximity clauses can be chained together: