Sorting
Order by Relevance
The score
column returned by paradedb.score
can be used to sort results by
BM25 relevance.
Order by Field
The result set can be ordered by any field in ASC
or DESC
order. By default, Postgres orders by ASC
.
Tiebreaking
Postgres can ORDER BY
multiple columns to break ties in BM25 scores. In the following query, rows with the same
score
will be sorted by rating
in descending order.
Fast Ordering
An ORDER BY...LIMIT
over a single text, numeric,
datetime, or boolean field is automatically “pushed down”
to the BM25 index if the ORDER BY
field is indexed as fast. This makes these queries significantly faster.
You can verify if an ORDER BY...LIMIT
was pushed down by running EXPLAIN
on the query. If pushdown occurred, a Custom Scan
with a
Sort Field
will appear in the query plan.
Ordering by Text Field
If a fast text field is indexed with the raw
normalizer, ORDER BY <text_field> LIMIT
can be pushed down.
If the lowercase
normalizer is used, then ORDER BY lower(<text_field>) LIMIT
(but not ORDER BY <text_field> LIMIT
)
can be pushed down.
Not all ORDER BY
s are pushed down. The following queries are not pushed down:
ORDER BY
s over multiple fields for tiebreaking.- Using
paradedb.score
with anORDER BY
over another field. ORDER BY
without aLIMIT
.
Was this page helpful?