ripaclub / sphinxsearch

Sphinx Search library provides SphinxQL indexing and searching features
BSD 2-Clause "Simplified" License
62 stars 10 forks source link

What is the difference between Ranking, Sorting, Matching Modes and Filtering in Sphinxsearch? #27

Closed ankitgoyal91 closed 10 years ago

ankitgoyal91 commented 10 years ago

I want to know what is the difference between ranking, sorting, matching modes and filtering in Sphinx and how can I do more than one thing at a time.

In documentation also, it is written you can do ranking and sorting simultaneously. How is it possible because if I rank then results will be arranged in some order and if I do sorting the results will be arranged in some different order.

If possible please explain using some example. I am using version 2.1.9.

Please don't refer me to Sphinx documentation. I have already read it.

Every answer is appreciated.

Thanks in advance.

leogr commented 10 years ago

In a SQL query you can combine them, like the following example:

SELECT x, weight() as w, w+x as myrank 
FROM myindex
WHERE x > 3 AND MATCH('foo')
ORDER by myrank DESC
OPTION ranker=bm25

In this way we're searching for all documents with attribute x greater than 3 and matching 'foo' using the bm25 ranker, then results will sorted by myrank that's a simple formula (the sum of x and the weight).

With our SphinxSearch library you can perform the query above in this way:

$select = new \SphinxSearch\Db\Sql\Select();
$select->columns(array('x', 'w' => new Expression('weight()'), 'myrank' => new Expression('w+x'))
           ->from('myindex')
           ->where(array('x > ?' => 3, new Match('?', 'foo'))
           ->order('myrank DESC')
           ->option(array('ranker' => 'bm25'));
leodido commented 10 years ago

@ankitgoyal91 Can we close?