简体   繁体   中英

Sphinx search best matching result

i am using sphinx search in one of my project. i need to make a search more accurate. for example my search is " i need a designer and seo for my Wordpress website". so what i want is get the best matching result which contains designer, seo and wordpress. here is my code

 $cl = new SphinxClient();
 $cl->SetServer('1.23.4', 456);
 $cl->SetMaxQueryTime(15000);
 $cl->SetMatchMode(SPH_SORT_RELEVANCE);
 $s->setMatchMode(SPH_MATCH_ANY);
 $s->SetLimits(0, 100);
 $res = $cl->query($searchterm,"products");

Please help me out and thanks in advance

Ranking isn't 'magic' - Sphinx follows an exact formula. However its subjective what formula to use, every application is different, and would benefit from different settings.

In your example its almost certainly you have loads of 'common' words in your query. eg all documents containing 'and' will match, regardless of what other words match!

Stopwords are a way of dealing with (but sometimes over simple), basically you add all the common words to the stoplist and then they are not used in the matching process.

Setting field-weights could also really help, as its less likly to have the 'common' words i the title for example (whereas the full text may have loads)

Or there's quorum operator, so could require a certain number of words (used in conjunction with stopwords or on its own!), for example could require at least 60% of the words. Rather than just one of the words.

Rather than stopwords, could just implement it virtually, ie prefilter the query and remove the common words.

(the stopword or common words, would usually be created manually from your particular index. There is a tool built into indexer to extract the common words from the index, which can use as a starting point)

Also just switching to SPH_MATCH_EXTENDED (can keep the 'OR' behaviour by using quorum operator), would give you flexiblility to choose a ranking mode (setRankingMode), which opens up even more possiblities for tweaking ranking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM