我想通过相关性对搜索结果进行排序,但标准技术对我的代码不起作用,因为它在查询中进行双重搜索检查以找到具有“匹配”和“喜欢”的搜索结果。如何使用以下代码执行此操作;
$qry = mysql_query("
SELECT *
FROM workdb
WHERE publish = 'Yes'
AND MATCH (workname, keyword1, keyword2, keyword3) AGAINST ('*$searched*' IN BOOLEAN
MODE)
OR publish = 'Yes'
AND (workname LIKE '%$searched%'
OR keyword1 LIKE '%$searched%'
OR keyword2 LIKE '%$searched%'
OR keyword3 LIKE '%$searched%')
LIMIT $offset, $rowsperpage
");
编辑:我想显示最相关和最不相关的结果。我使用Math和LIKE的原因是不要错过搜索中任何匹配的元素。
EDIT2:确定要清楚,我在数据库行中有一个工作名称和3个关键字,所以我希望得到与我搜索到的文本/单词匹配最佳的那些并将它们放入订购最喜欢最不喜欢/大多数匹配至少匹配。
答案 0 :(得分:-1)
如果有人遇到同样的问题,答案就在这里。没有人理解我,而是他们贬低。
mysql_query("SELECT *,
(MATCH (workname) AGAINST ('*$searched*' IN BOOLEAN MODE)
AND
(workname LIKE '%$searched%'))
AS relevancy
FROM workdb
WHERE publish='Yes'
AND
(MATCH (workname, keyword1, keyword2, keyword3) AGAINST ('*$searched*' IN BOOLEAN MODE)
OR
(workname LIKE '%$searched%' OR keyword1 LIKE '%$searched%' OR keyword2 LIKE '%$searched%' OR keyword3 LIKE '%$searched%'))
ORDER BY relevancy DESC
LIMIT $offset, $rowsperpage");