简体   繁体   English

MySQL对多个关键字进行全文搜索

[英]MySQL Full text search on multiple keywords one-many

I'm trying to use MySQL's FTS to search through indexed content to look for certain keywords. 我正在尝试使用MySQL的FTS来搜索索引内容以查找某些关键字。 For what I'm trying to make, it needs either one or more of the keywords in the text, and the keywords must be exact word matches. 对于我要制作的内容,它需要文本中的一个或多个关键字,并且关键字必须与单词完全匹配。 However, it doesn't matter if the keywords is in the middle of another word, for example, when searching for "STACK", it should match: 但是,关键字是否在另一个单词的中间并不重要,例如,在搜索“ STACK”时,它应该匹配:

  1. Hi, I have a stack of overflows 嗨,我堆满了
  2. Stacked against the wall 叠放在墙上
  3. These bookcases are overstacked completely 这些书架完全堆放了

I was using the following method before: 我之前使用以下方法:

SELECT ... FROM ... WHERE text LIKE '%keyword1%' OR LIKE '%keyword2%' OR LIKE '%keyword3%'

This would return any text that would contain any of the keywords. 这将返回包含任何关键字的任何文本。 However, this began to slow down pretty much everything, because most of the indexed content is big (stored in blob) and I have over 500 of those rows to index through. 但是,这开始使几乎所有内容变慢,因为大多数索引内容很大(存储在blob中),并且我有500多个行可供索引。 As Like is not using any indexing with this method, I tried converting to FTS using the following: 由于Like不使用此方法使用任何索引,因此我尝试使用以下方法转换为FTS:

SELECT ... FROM ... WHERE MATCH(text) AGAINST ('+keyword1 +keyword2 +keyword3' IN BOOLEAN MODE)

This worked good with single keywords, but when entering multiple keywords, this fails because FTS with the + operand NEEDS to find a match with the given words. 这对于单个关键字效果很好,但是当输入多个关键字时,这会失败,因为带有+操作数NEEDS的FTS会找到与给定单词的匹配项。 But without these keywords, the FTS matches fuzzy results, not exact results. 但是,如果没有这些关键字,FTS将匹配模糊结果,而不是精确结果。 I end up with content being missed that most definitly contains the keywords. 我最终错过了最明确包含关键字的内容。

What can I use to get all content that contain either one or more of the axact keywords? 如何使用所有包含一个或多个axact关键字的内容?

尝试这样的事情:

SELECT * FROM table MATCH (text) AGAINST ('+"keyword1" +"keyword2"' IN BOOLEAN MODE)

It sounds like you are looking for something like the following: 听起来您正在寻找类似以下内容的东西:

SELECT ... FROM ... 
WHERE MATCH(text) AGAINST ('+keyword1' IN BOOLEAN MODE) 
OR MATCH(text) AGAINST ('+keyword2' IN BOOLEAN MODE)
OR MATCH(text) AGAINST ('+keyword3' IN BOOLEAN MODE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM