0
votes

I have a similar question here: Sphinx search ranking broken?, but thought I'd ask a simpler version of it to see if I got any hits.

Does anyone know how to affect the weights in Sphinx search results? Specifically for exact matches.

I know changing the ranking mode gives you different weight scales, but most of the hits I'm getting have the same weight, for example searching for "once" produces disparaging results like:

"once we were warriors" weight = 1637
"once" weight = 1637
"Once upon a time in the west" weight = 1637

Surely, at least the first one should have a different weight since it's an exact match.

Been fighting this for a couple of days, any help would be very welcome.

5

5 Answers

2
votes

The same type of a question was asked in the Sphinx forum.

$cl->setMatchMode(SPH_MATCH_EXTENDED);
$cl->setRankMode(SPH_RANK_WORDCOUNT);

$cl->Query('"^public work place$ | "public work place" | (public work place) | "public work place"/1 | (*public* *work* *place*)',$index);

This works for me and getting the exact match first and then the phrase etc. in order.

NOTE: here instead of getting different weight the result order is set according to the query provided. I think it is better get the result without changing different weight that will require more computation, and ultimately save time and money. :-)

This works in my system and tested (Sphinx 0.9.9-release -r2117 ).


1
votes

I just tested SPH_RANK_SP04 with this sort of thing, seems to work.

I've upgraded this testing tool to use sphinx 2.01 (so that SPH04 is available)

http://www.nearby.org.uk/sphinx/searchtest.php?q=one&ranking=7

notice 'one' on its own gets the highest possible weight.

0
votes

Similar discussion here: Sphinx search ranking broken?. I created another question in the hopes that by simplifying things I would get more answers since none were forthcoming.

Turns out that SPH_RANK_SPH04 is not included in the sphinxapi.php file in version 0.9.9 (release)!!! So even though you're calling it it's not taken into account and furthermore does not produce an error.

This is terrible because it makes it very hard to troubleshoot.

I've posted this as the answer in the hopes that it helps someone else. We lost almost 2 days going crazy over this until we figured it out.

Furthermore, there is a bug in 2.0.1 which doesn't really bring some exact matches to the front, for that you need 2.0.2 (which you need to get from SVN) or above, but I'd be very weary of using experimental versions in production.

Hopefully the Sphinx developers will take care of this soon.

PS Looking back at the developer diaries, it does say:

"As of 1.10-beta, Sphinx has 8 different rankers"

We upgraded from 0.9.9 to 2.0.1 and must have left the api file behind, and in desperation I never even checked this. It would still be nice for Sphinx to throw an error if the ranking mode doesn't exist (as it does for other modes such as matching), and the 2.0.1 bug is still there as far as we can tell in our tests.

0
votes

i've encountered the same issue with the PECL Sphinx module, and i think i've solved this by defining the missing constants:

define ( "SPH_RANK_PROXIMITY", 4 );
define ( "SPH_RANK_MATCHANY", 5 );
define ( "SPH_RANK_FIELDMASK", 6 );
define ( "SPH_RANK_SPH04", 7 );
define ( "SPH_RANK_EXPR", 8 );
define ( "SPH_RANK_TOTAL",9 );

Hope this help.