samedi 30 décembre 2017

Is there a way to randomize search results (record ids) with Sphinx?

I have a complex SphinxQL query which, at the end, orders results by a specific field, Preferred, so that all records with that indexed value of Preferred=1 come before all records w Preferred=0. I also order by weight() so basically I end up with:

Select * from idx_X where MATCH('various parameters') ORDER by Preferred DESC,Weight() Desc

The problem is that, though Preferred records come first I end up with records sorted by ID which puts results from one field, Vendor, in blocks so for instance I get:

Beta Shipping Beta Shipping Beta Shipping Acme Widgets Acme Widgets Acme Widgets Acme Widgets Acme Widgets

Which doesn't serve my purposes in this case well (often one 'Vendor' will have 1000 results)

So I'm looking to essentially do:

ORDER BY Preferred DESC,weight() DESC,ID RANDOM

So that after getting to Preferred Vendors whose weight is (e.g.) 100, I will get random Vendors vs blocks of them.




Aucun commentaire:

Enregistrer un commentaire