0

I have a Sphinx search on a django site that is running very well. It finds excellent matches for all sorts of queries. I would like to be able to give a boost in ranking to newer results. Quite often articles that are many years old will rank higher than brand new articles. The older articles contain the search term more often, so have higher relevancy, but the new articles are still very relevant, so I would like them to appear first.

I tried to read the Sphinx documentation about weighting, but it is incredibly confusing and filled with terminology that I don't really understand. I want to keep the search mostly the same as it is, I just want to give a slight boost in ranking to results with more recent pub_dates.

Apreche
  • 30,042
  • 8
  • 41
  • 52

3 Answers3

4

Using SPH_SORT_EXPR you can change sorting by an arithmetic expression, like:

$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + IF(pub_date > strtotime('2011-01-01), 50, 0) );

In this expression, articles which was published starting from 1 Jan 2011 will gain +50 to the weight.

Iaroslav Vorozhko
  • 1,719
  • 14
  • 12
  • This doesn't work because the date is always changing. It can't be some arbitrary cut-off date. It needs a general sliding scale that goes all the way back through history. – Apreche Feb 14 '12 at 13:29
  • 1
    How could I write this using the PDO mysql way of querying? – digout Apr 03 '18 at 13:20
1

$cl->SetSortMode ( SPH_SORT_EXPR, "@id" ); this gives you a ramp--the more recent, the more weight. Simply do @id * 2 to double the effect or / 2 to dampen it.

This wouldn't work, because using absolute values it is hard to predict the results. For example two posts with id 100 and id 99000 respective, but with very good weight for id 100 and very bad weight for id 99000 will up the id 99000.

Iaroslav Vorozhko
  • 1,719
  • 14
  • 12
0

$cl->SetSortMode ( SPH_SORT_EXPR, "@id" ); this gives you a ramp--the more recent, the more weight. Simply do @id * 2 to double the effect or / 2 to dampen it.

servermanfail
  • 2,532
  • 20
  • 21