Take the 2-minute tour ×

I am using sphinx 2.0.

I want to achieve following results :

  1. user will input tags with other search terms, documents associated with user input tags should come on top, sorted by distance.
  2. After that documents does not contain those tags sorted by distance.

What i am doing:

I am searching on different parameters at the same time using like @name , @tag, @streetname etc.so i am using below


and sorting the result by distance using $cl->SetSortMode(SPH_SORT_EXTENDED, '@geodist asc');

tag filed can contain multiple values i am using OR operator to get the desired results.

If i search for only @tags then i am able to achieve the requirement i have mentioned. but if user input is @tag food|dinner @city london @name taxi

then result with name: London Taxi, street: London comes on top or some other position breaking the sorting order by lat-long. because London is there in two parameters.i just want to sort by tag, do not want to include the weight of other search terms in sorting order.

Ranking mode is : $cl->setRankingMode(SPH_RANK_PROXIMITY_BM25);

any suggestion to overcome this issue ? or any other way to implement it.

Many Thanks.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I think the way to solve this would be to arrange for matches on the tag field to rank way way higher. Would have to test it but something like this...

$cl->setFieldWeights(array('tags' => 100000));

$cl->setSelect("*,IF(@weight>100000,1,0) AS matchtags");

$cl->SetSortMode(SPH_SORT_EXTENDED, 'matchtags DESC, @geodist ASC');
share|improve this answer
add comment

Your Answer


