2 回答
TA贡献1776条经验 获得超12个赞
该查询将整个单词的记录排名更高,但car,cards排名与 just 相同,car因此它仍然不是最佳的。
SELECT id, search_tags,
MATCH(search_tags) AGAINST('car *') +
MATCH(search_tags) AGAINST('car') AS relevance_rank
FROM images
WHERE MATCH(search_tags) AGAINST('car *')
OR MATCH(search_tags) AGAINST('car')
ORDER BY 3 DESC
+----+---------------------+----------------+
| 身份证 | search_tags | 相关性_排名|
+----+---------------------+----------------+
| 12 | 汽车,卡片,食物,代码| 0.1677478002 |
| 13 | 汽车,水,天空| 高分辨率照片| CLIPARTO 0.1677478002 |
| 11 | 载体,食物,饮料| 高分辨率照片| CLIPARTO 0.0093915509 |
+----+---------------------+----------------+
下一个查询还会查看确切单词在字符串中出现的次数。更好的结果,但可能有点太复杂了。
SELECT id, search_tags,
MATCH(search_tags) AGAINST('car *') +
MATCH(search_tags) AGAINST('car') AS relevance_rank,
LENGTH(search_tags) -
LENGTH(REPLACE(search_tags, 'car', space(LENGTH('car')) -1 )) AS occurences
FROM images
WHERE MATCH(search_tags) AGAINST('car *')
OR MATCH(search_tags) AGAINST('car')
ORDER BY 3 DESC, 4 DESC
+----+---------------------+-----+----- -------+
| 身份证 | search_tags | 相关性_排名| 发生|
+----+---------------------+-----+----- -------+
| 12 | 汽车,卡片,食物,代码| 0.1677478002 | 2 |
| 13 | 汽车,水,天空| 高分辨率照片| CLIPARTO 0.1677478002 | 1 |
| 11 | 载体,食物,饮料| 高分辨率照片| CLIPARTO 0.0093915509 | 1 |
+----+---------------------+-----+----- -------+
TA贡献1850条经验 获得超11个赞
使用Union时应该工作:
SELECT
id,
search_tags,
MATCH(search_tags) AGAINST(REPLACE(concat("'car'"," ")," "," ") IN BOOLEAN MODE) AS relevance_rank,
1 as prio -- sort by priority first
FROM
images
WHERE
MATCH(search_tags) AGAINST(REPLACE(concat("'car'"," ")," "," ") IN BOOLEAN MODE)
ORDER BY relevance_rank DESC
UNION SELECT
id,
search_tags,
MATCH(search_tags) AGAINST(REPLACE(concat("'car'"," ")," ","* ") IN BOOLEAN MODE) AS relevance_rank,
2 as prio -- sort by priority first
FROM
images
WHERE
MATCH(search_tags) AGAINST(REPLACE(concat("'car'"," ")," ","* ") IN BOOLEAN MODE)
ORDER BY prio, relevance_rank DESC;
- 2 回答
- 0 关注
- 186 浏览
添加回答
举报