0

I have a mysql database with a simple table named item. Item contains the following fields and has 55,000 records:

ID (PK) Description (INNODB FULL TEXT) DATE

By design i am forced to index all the way down to 1 character words since some descriptions contain names such as Item 1 a 2 42 where the spaces MUST be kept intact. I am running a full text search against this table and here are my results for the following code:

Select ID, Description, Date
From Item
WHERE date > DATE_SUB(NOW(), INTERVAL 15 MONTH)
AND description LIKE CONCAT('%item 1 2 a 4%')
AND MATCH (description) AGAINST ('+item +1 +2 +a +4' in boolean mode);

This Query returns in 1.2 seconds. However, once i add the following proximity search to the query my return time goes through the roof:

Select ID, Description, Date
From Item
WHERE date > DATE_SUB(NOW(), INTERVAL 15 MONTH)
AND description LIKE ('%item%')
AND MATCH (description) AGAINST ('+item +1 +2 +a +4' in boolean mode)
AND MATCH (description) AGAINST ('"1 2 a 4" @30' in boolean mode);

This Query returns in 54 seconds! The proximity search is a must to my query since i need to make sure i find "item 1 2 a" and not "item 1 2 48884848 222 a" which would be totally different. Proximity search runs a lot better when the words are more than 1 characters, but there are some circumstances that would call for a user typing in 1 character words. Is there ANYTHING else i can do that would be an alternative to proximity searching of full-text innodb but have much better performance? If there is nothing else in MYSQL, i am open to using something to integrate to give me a better proximity search (i am on windows though).

thanks!

4

2 回答 2

2

LIKE条件使您的全文索引失效。替换条件

description LIKE CONCAT('%item 1 2 a 4%') -- and why CONCAT() anyways?

... 和

MATCH (description) AGAINST ('"item 1 2 a 4"' IN BOOLEAN MODE)

您的第二个条件没有用,因为它与第一个条件重叠(您已经通过确切的字符串“item 1 2 a 4”过滤,这些行始终匹配 '+item +1 +2 +a +4')。

于 2013-08-13T10:12:08.130 回答
0

我们可以使用以下重写的查询吗?

SELECT ID, Description, Date
FROM Item
WHERE date > DATE_SUB(NOW(), INTERVAL 15 MONTH)
AND MATCH (description) AGAINST ('"1 2 a 4" @30 +item' in boolean mode);

接近很慢,因为它很复杂。建议您使用不超过两个词进行邻近搜索。随着词数的增加,查询时间增加更多。

于 2014-02-14T01:51:05.743 回答