0

I seem to have had my question answered on how to order results by relevance using OPTION field_weights. However I'm finding it does not work when using an ORDER by in the same SphinxQL Query e.g.

Select * from Items where MATCH('@(Listing_Title) London @(Listing_Title,Description) Jack') ORDER By Featured_Flag DESC OPTION field_weights=(Author=1000)

Which basically is trying to say:

"Find me all the books with 'Jack' and 'London', put all the books by featured sellers first and non-features sellers after, and in each group put the records where both 'Jack' and 'London' appear in the Listing_Title itself"

So a sample return should look like this where the field order is:

Listing_Title                Description                      Featured_Flag

Jack London Books for Sale   New buy now!                     1
London, Steinbeck and more   Call of the Wild by Jack London  1
Jack London Classics!        In great shape write or call     0
Call of Wild - London        THE Jack London                  0

Once I add the ORDER by Featured_Flag DESC however the field_weights=(Listing_Title=1000) is no longer obeyed.

Is there some other way to do this? I've read that querying two indexes can act as a union perhaps a Listing_Title_Index and a All_Index would work?

Community
  • 1
  • 1
user3649739
  • 1,829
  • 2
  • 18
  • 28

1 Answers1

0

Well, the field_weights just modify the computed weight (giving extra weight to specific field(s). So need to ensure that WEIGHT() is still factored into your ORDER BY somehow.

If there is no ORDER BY (and there is a MATCH(...)) then sphinx will automatically order by WEIGHT(), but if supply a sort order, need to add it yourself

For example:

... ORDER By Featured_Flag DESC, WEIGHT() DESC
barryhunter
  • 20,886
  • 3
  • 30
  • 43
  • Yeah after adding `Weight()` to the select i noticed that (and it is always the weight of the current weighting so adding a `field_weights1 changes `Weight()`. Once I figured that out I just add to manually add the Weight() to the Order so that I could combine it with other field orders. – user3649739 Mar 29 '17 at 13:28