Search code examples
searchsphinxmodesphinxql

SphinxQL - Perfect Search Mode for 1 to 4 words


I'm working on a project with Sphinx Search Engine using SphinxQL. My problem is the following:

This is my sphinxql query:

"SELECT *, country FROM all_gebrauchte_products WHERE MATCH('@searchtext (".$searchQuery.")') AND country='".$where."' ORDER BY WEIGHT() DESC LIMIT ".$page.", ".$limit." OPTION ranker=expr('sum(lcs)')"

The result differs very strongly like:

Honda => 50 results 
Honda CBR => 9 results 
Honda CBR 1000 => 2 results 

This is my MySQL query:

SELECT COUNT(*) FROM all_gebrauchte_products WHERE MATCH(gebr_id, gebr_hersteller, gebr_modell, gebr_ukat, gebr_kat, gebr_bemerkung) AGAINST ('".$searchQuery."' IN BOOLEAN MODE);

The results is:

Honda => 67 results 
Honda CBR => 67 results 
Honda CBR 1000 => 84 results 

The MySQL query works in Boolean Mode - so query for Honda CBR 1000 also finds Honda VTR 1000, as I think...

So, what would be the best search mode to come near to the second result set? Can anybody explain me what would be the perfect mode and how (example) to write the sphinxql query in the right way?

Thnx. in advance...


Solution

  • The main difference is MySQLs 'Boolean' modes implicit operator is OR. A multi word query just requires one of the words (unless prefix with +)

    But Sphinxes 'extended match' mode (which is what sphinxQL uses), the implicit operator is AND. So its requiring ALL the words.

    Could use he quorum operator to get a default 'OR' behaviour

    ... MATCH('@searchtext (\"".$searchQuery."\"/1)') ... 
    

    ie only one of the words is required.

    --

    The MySQL query works in Boolean Mode - so query for Honda CBR 1000 also finds Honda VTR 1000, as I think...

    Well yes. But because just one word required, also finding all the documents with say '1000' them, even if not Honda. Which is why the three word has more documents.