MySQL fulltext search only works in BOOLEAN Mode. How get relevancy?
I want to search in Natural Language Mode to order results by relevancy, but my query only works with BOOLEAN Mode selector. If I use the query without BOOLEAN I get no results. Any idea why this does not work? Or idea how to get results by relevancy (most matched keywords first) with BOOELAN?
My query:
SELECT *,
MATCH(md.keywords) AGAINST('$meta[keywords]' IN BOOLEAN MODE) AS score
FROM
meta_data AS md
INNER JOIN
sites AS si ON md.domain = si.domain && si.domain != '$data[domain]'
WHERE
MATCH(md.keywords) AGAINST('$meta[keywords]' IN BOOLEAN MODE)
ORDER BY score Desc
LIMIT 25
Database is MyISAM
and I have altered mysql table for fulltext search
FULLTEXT KEY `title` (`title`,`description`,`keywords`)
Change your query to
SELECT *, MATCH(md.keywords) AGAINST('$meta[keywords]') AS score
FROM
meta_data AS md
INNER JOIN sites AS si ON md.domain = si.domain && si.domain != '$data[domain]'
WHERE
MATCH(md.keywords) AGAINST('$meta[keywords]' IN BOOLEAN MODE)
ORDER BY score DESC
LIMIT 25
The
MATCH(md.keywords) AGAINST('$meta[keywords]') AS score
will return the relevancy score of the search term and
ORDER BY score DESC
will display your results in descending order (ie highest score first)
链接地址: http://www.djcxy.com/p/13108.html上一篇: 关于Mysql全文搜索