在 MySQL full-text 搜索中,如何搜索仅包含特定单词的文档?

In MySQL full-text search, how to search for documents that ONLY contain the specific words?

我有 table 个标题,我只想找到完全由单词子集组成的标题。

例如,

SELECT title
FROM my_titles_table WHERE MATCH (title) AGAINST ('word1 word2 word3 ... wordN' IN NATURAL LANGUAGE MODE)

我想查找由 word1 word2 word3 ... wordN 或其子集组成的所有标题,但没有其他词。

例如,如果我的查询是 "how to train your dragon" 作为我的话,那么我想找到像 "dragon" 或 "train your dragon" 或 "your dragon to train" 这样的标题,而不是 "dungeons and dragons" 因为单词 "dungeon" 不在我的查询中。

我认为全文搜索不支持此功能。事实上,很难想出一种蛮力的方法来做到这一点。

这是一种暴力破解方法:

where trim(replace(replace(replace(title, $word1, ''), $word2), ''), $word3, '')) = ''

这并不完美,因为 "pine apple" 将匹配 "pine apple"。

嗯嗯。 . .正则表达式还有另一种选择:

 where title like concat('^(', replace('word1 word2 word3', ' ', '|'),
                          '[ ]*)+$)

也就是说,匹配必须从字符串的开头和结尾开始,中间的单词必须全部匹配。

据我所知,没有办法加快这样的查询。