sphinxsphinxql

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


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?


Solution

  • 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.