PJ Bergeron
PJ Bergeron

Reputation: 2998

Sorting results with sphinx

I'm using Sphinx 2.0.5.

sphinx.config:

index test
{
    type      = mysql
    sql_host  = host
    sql_user  = user
    sql_pass  = pass
    sql_db    = db

    sql_query = SELECT id, string \
                FROM table
}

sphinx.php:

$sphinx = new SphinxClient();

$sphinx->SetServer('localhost', 3312);
$sphinx->SetConnectTimeout(1);

$sphinx->SetLimits(0, 15);

$sphinx->SetMatchMode(SPH_MATCH_ALL);
$ret = $sphinx->query($query, 'index');

In "string" there are lines like

"mouse, screen, keyboard, green house"
"green house, computer, keyboard, green house"

I'd like to sort by :
1- the number of different keywords found in the line
2- the total number of keywords found in the line

For example, if I search for "green house", I'd like to get "green house, computer, keyboard, green house" in first. But if I search for "green house screen", "mouse, screen, keyboard, green house" should be in first.

Do you have an idea of what kind of sorting I should use ?

Thanks.

Upvotes: 0

Views: 504

Answers (1)

barryhunter
barryhunter

Reputation: 21091

Personally I would put , into phrase_boundary http://sphinxsearch.com/docs/current.html#conf-phrase-boundary

which seperates phrases into seperate boundaries. Can now use primoxy to affect results.

Then would write the search something like

$cl->setMatchMode(SPH_MATCH_EXTENDED);
$cl->setRankingMode(SPH_RANK_WORDCOUNT);
$cl->Query('"green house"~10 | "green house" | (green house)',$index);

Can choose exactly what factors you like, to affect the results. Gets more complicated with 3(or more!) word queries, as have to expand all the combinations into the query.

(I'm not sure if this results in your exact specifications - to be honest they arent clear - but this is a general solution for this type of situation - matching tag lists)

Upvotes: 1

Related Questions