MySQL: Is it possible to obtain words of a fulltext index?

笑着哭i 提交于 2019-12-25 09:19:08

问题


I like to sort a BOOLEAN wildcard search by relevance. As BOOLEAN has only a binary score we need to use the NATURAL mode to obtain a weight score. But NATURAL does not support operators so it will not return any results (score = 0):

mysql>SELECT
        topic_id,
        MATCH(topic_text) AGAINST('tunin') AS score
    FROM
        topics_search
    WHERE
        MATCH(topic_text) AGAINST('tunin*' IN BOOLEAN MODE)
    ORDER BY
        score DESC
    LIMIT 10
+----------+----------+
| topic_id | score    |
+----------+----------+
| 2        | 0        |
| 6        | 0        |
| 16       | 0        |
| 17       | 0        |
| 18       | 0        |
| 24       | 0        |
| 26       | 0        |
| 27       | 0        |
| 31       | 0        |
| 32       | 0        |
+----------+----------+
10 rows in set (202 ms)

I could use LIKE '%tunin%' but this won't give me a score.

Question
Is it possible to obtain all the words that are part of the fulltext index, that were hit through the wildcard search?

Example:

mysql>SELECT
        fulltext_index_words
    FROM
        topics_search
    WHERE
        MATCH(topic_text) AGAINST('tunin*' IN BOOLEAN MODE)
+----------------------+
| fulltext_index_words |
+----------------------+
| tuning               |
| tunings              |
+----------------------+
2 rows in set (1 ms)

来源:https://stackoverflow.com/questions/42101851/mysql-is-it-possible-to-obtain-words-of-a-fulltext-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!