dexterdeng
dexterdeng

Reputation: 249

how can I add weight to keyword for thinking sphinx

I did such search,

`  Comment.search "aabbb "`

and I want to get the results which contain "ab" too.; So I did that way:

`  Comment.search "aabbb ab"`

but I found the results aabbb and ab are mixed , in fact, I want to make the results which match aabbb shows before ab, in other words, have a higher priority.

I know sphinx can add weight the fields of the table. for example add 10 to comments's name, 20 to comment's content. but is it possible to add weight to the query works?

Upvotes: 0

Views: 583

Answers (2)

alex
alex

Reputation: 580

Unfortunately this is not possible with sphinx yet but you can add similar behavior on a query by adding multiple times the keyword you want to weight.

For example:

"aabbb | aabbb | ab"
The aabbb is twice more important than ab

Upvotes: 1

pat
pat

Reputation: 16226

Sphinx has no ability to weight certain search phrases, I'm afraid - so what you're trying to do is not possible.

It's also worth noting that Sphinx uses AND logic by default - if you want results that match either aabbb OR ab, you'll probably want to use the :any match mode:

Comment.search "aabbb ab", :match_mode => :any

Upvotes: 0

Related Questions