X
X
Xrist1An2015-11-24 05:09:31
PHP
Xrist1An, 2015-11-24 05:09:31

How to influence the relevance of MySQL fulltext search?

Columns in the table: id, text, source I
use the usual query:

SELECT * FROM `articles` WHERE MATCH (text) AGAINST ('database');

...how can I make search results\rows with the word "auto" in the 'source' column ranked with higher priority than other rows?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-11-24
@Xrist1An

Lines with 'auto' are always in front:

SELECT * 
    FROM (
        SELECT *, MATCH `text` AGAINST('database') AS `score`
            FROM `articles`
    ) AS `t`
    WHERE `score` > 0
    ORDER BY `source` != 'auto', `score`

Lines with 'auto' have more weight (+0.5):
SELECT *
    FROM (
        SELECT *, MATCH `text` AGAINST('database') AS `score`
            FROM `articles`
    ) AS `t`
    WHERE `score` > 0
    ORDER BY `score`+(`source` = 'auto')*0.5 DESC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question