M
M
MIC2016-03-25 11:10:59
Sphinx
MIC, 2016-03-25 11:10:59

Sphinx. How to give weight to some words in a query?

I display related posts and make it a query

SELECT id, WEIGHT() as relevance FROM posts 
WHERE MATCH('(@content world|peace|leo)') 
ORDER BY relevance DESC 
OPTION ranker = 'bm25'

In this case everything works fine, but I still need to add topics from the current user and I would like to do something like
SELECT id, WEIGHT() as relevance FROM posts 
WHERE MATCH('(@content world|peace|leo) (@content_2 photography)') 
ORDER BY relevance DESC 
OPTION ranker = 'bm25', field_weights=(content=10,content_2=5)

But how to do it without duplicating `content` in `content_2`? After all, this will double the index.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georgy Eremeev, 2016-04-24
@MIC

SELECT id, WEIGHT() as relevance FROM posts 
WHERE MATCH('(@content world|peace|leo^10) (@content photography^5)') 
ORDER BY relevance DESC 
OPTION ranker = 'bm25'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question