我想在自然语言模式中搜索按相关性排序结果,但我的查询仅适用于BOOLEAN模式选择器。如果我使用没有BOOLEAN的查询,我得不到任何结果。知道为什么这不起作用吗?或者想一想如何通过相关性(首先匹配最多的关键字)与BOOELAN获得结果?
我的查询:
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
数据库是MyISAM
,我已经更改了mysql表以进行全文搜索
FULLTEXT KEY `title` (`title`,`description`,`keywords`)
答案 0 :(得分:2)
将您的查询更改为
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
MATCH(md.keywords) AGAINST('$meta[keywords]') AS score
将返回搜索字词和
的相关性分数 ORDER BY score DESC
将按降序显示结果(即最高得分)