mysql全文不准确

z9ju0rcb  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(406)

我有一个以id、topic、description、image url为列的表。条目如下

id   topic               description    image_url
1    People and blogs    TownHall       http://...
2    People and blogs 2  ......         .......
3    Blogs               .......        .......
4    Good                ......         ......

当我搜索博客作为查询输入时

SELECT * FROM people 
WHERE MATCH(topic,descript) AGAINST ("blogs" WITH QUERY EXPANSION)

我得到的结果是

1  People and blogs    TownHall    http://.../
2  People and blogs 2  ......      ......./
3  Blogs               .......     ......./

第三行应该排在第一位,因为它是确切的单词(blogs),其他行应该排在后面。。
请帮我调试这个。

cdmah0mi

cdmah0mi1#

试试下面的sql,它会解决你的问题。

SELECT people.*
  FROM people
order by MATCH(topic,descript) AGAINST ("blogs" WITH QUERY EXPANSION) asc;

输出:

+------+--------------------+-------------+
| id   | topic              | descript    |
+------+--------------------+-------------+
|    3 | Blogs              | ........    |
|    2 | People and blogs 2 | ........    |
|    1 | People and blogs   | TownHall    |
+------+--------------------+-------------+
mzaanser

mzaanser2#

尝试以下操作:

SELECT * FROM people, 
MATCH(topic,descript) AGAINST ("blogs" WITH QUERY EXPANSION) AS score
WHERE score > 0
ORDER BY score DESC

相关问题