The query builder API is a set of functions to compose and tune complex text search queries. Unlike the text-based query syntax, they’re well suited for ORM tools and prepared statements. They also contain some advanced queries not available to text-based queries.

Basic Usage

The search function that’s generated for your index can accept query objects instead of a query string. Nearly all the query types implemented in Tantivy, our underlying search engine, are exposed to Postgres. A query string itself is parsed into a query object, and can be used anywhere in a query tree with paradedb.parse.

paradedb.parse is implicitly performed if a query string is passed directly to the search function. These two queries are identical:

SELECT * FROM search_idx.search('description:shoes');
SELECT * FROM search_idx.search(query => paradedb.parse('description:shoes'));

Composable Query Objects

These query objects are composable, which allows for arbitrarily fine-grained queries. For instance, the following query looks for documents containing either the term running or shoes and boosts the relevance of documents matching shoes.

SELECT * FROM search_idx.search(
    query => paradedb.boolean(
        should => ARRAY[
            paradedb.boost(query => paradedb.parse('description:shoes'), boost => 2.0),
            paradedb.term(field => 'description', value => 'running')
        ]
    )
);