How do ordering by rank and fields relate to each other in Sphinx search?

362 Views Asked by At

Suppose I have a query like this:

SELECT <somefields>
FROM example
ORDER BY somefield ASC
OPTION ranker=bm25

This seems contradictory. How is it going to sort? By somefield only? Or by BM25 rank only? Or both? If both then which is the most important? Can I use both like somefield ASC, rank DESC or rank DESC, somefield ASC? How can I disable sorting altogether?

1

There are 1 best solutions below

2
barryhunter On BEST ANSWER

Ordering by somefield only. There is an implicit ORDER BY WEIGHT() DESC, but if set any order, it completely overrides the implicit value.

... can choose to use weight in multisort, eg

ORDER BY somefield ASC, WEIGHT() DESC

In your example query, the actual calculated weight would be unused. Its not in sort, its not in the select. In fact sphinx might internally change to the 'none' ranker anyway, but can choose it explicitly

OPTION ranker=none

THere is no 'completely unsorted', can't say ORDER BY NULL or whatever.