L
L
Lev K2017-02-13 09:49:10
Sphinx
Lev K, 2017-02-13 09:49:10

Yii2 sphinx ranker how to implement correctly?

Hello.
Created an index model and want to do a full text search. But it is not possible to implement your ranker.
There is an attribute in the index: weight, which will correct the output as I need. In general, you need to multiply the overall rating (collected from the options) by the rating in the document.
Tried like this:

$result = GeoIndex::find()
            ->select(['item1_id', 'item2_id', 'item3_id', 'item3_name'])
            ->match(new MatchExpression('@(item1_name,item2_name,item3_name) :match /1', [':match' => $data]))
            ->orderBy('weight() DESC')
            ->addOptions(['field_weights'=> ['item1_name' => 3, 'item2_name' => 2, 'item3_name' => 1]])
            ->addOptions(['ranker' => "expr('(sum(lcs*user_weight)*1000+bm25)*weight'" ])
            ->one();

Gives an error:
unknown ranker 'expr(\'(sum(lcs*user_weight)*1000+bm25)*weight\''
I also tried this:
->addOptions(['ranker' => new \yii\db\Expression ("expr('(sum(lcs*user_weight)*1000+bm25)*weight'") ])
Ошибка:
sphinxql: syntax error, unexpected $end, expecting ')' near ''(sum(lcs*user_weight)*1000+bm25)*weight''

->addOptions(['ranker' => new \yii\sphinx\MatchExpression ("expr('(sum(lcs*user_weight)*1000+bm25)*weight'") ])
Ошибка:
Exception 'yii\db\Exception' with message 'Object of class yii\sphinx\MatchExpression could not be converted to string
Failed to prepare SphinxQL: SELECT `item1_id`, `item2_id`, `item3_id`, `item3_name` FROM `index` WHERE MATCH(:qp0) ORDER BY weight() DESC OPTION field_weights = (item1_name = :qp1, item2_name = :qp2, item3_name = :qp3), ranker = :qp4'

in /var/www/project/vendor/yiisoft/yii2-sphinx/Command.php:280

As a result, the 2nd option turned out to be correct, with an amendment from the comment. The point was that weight is a reserved word, I changed the name of the attribute and everything worked!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev K, 2017-02-13
@Leffken

The second option is still closest to the truth, but it is impossible to multiply by the attribute of the document.

//Не работает, 
->addOptions(['ranker' => new Expression("expr('(sum(lcs*user_weight)*1000+bm25)*weight')") ])
Ошибка : 
index lite_geo_index_fr: Sphinx expr: syntax error, unexpected $end, expecting '(' near ''

//Работает
->addOptions(['ranker' => new Expression("expr('(sum(lcs*user_weight)*1000+bm25)')") ])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question