MySQL-布尔模式下的全文+;使用视图字段的相关性

MySQL-布尔模式下的全文+;使用视图字段的相关性,mysql,database-design,full-text-search,Mysql,Database Design,Full Text Search,我有下表: CREATE TABLE IF NOT EXISTS `search` ( `id` BIGINT(16) NOT NULL AUTO_INCREMENT PRIMARY KEY, `string` TEXT NOT NULL, `views` BIGINT(16) NOT NULL, FULLTEXT(string) ) ENGINE=MyISAM; 它总共有5395939个条目。要对术语(如“a”)执行搜索,我使用以下查询: SELECT * F

我有下表:

CREATE TABLE IF NOT EXISTS `search`
(
    `id` BIGINT(16) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `string` TEXT NOT NULL,
    `views` BIGINT(16) NOT NULL,
    FULLTEXT(string)
) ENGINE=MyISAM;
它总共有5395939个条目。要对术语(如“a”)执行搜索,我使用以下查询:

SELECT * FROM `search` WHERE MATCH(string) AGAINST('+a*' IN BOOLEAN MODE) ORDER BY `views` DESC LIMIT 10
但是它真的很慢=(。上面的查询需要15.4423秒来执行。显然,如果不按
视图排序,它的速度很快,这需要不到0.002s的时间

我使用的是ft\u min\u word\u len=1和ft\u stopword\u文件=

有没有什么方法可以在全文搜索中使用视图作为相关性,而不会太慢?例如,我希望搜索词“a b”与“big apple”匹配,而不是“ibg apple”(只需要搜索前缀匹配)


谢谢

因为没有人回答我的问题,所以我发布了我的解决方案(这不是我在谷歌搜索时希望看到的,因为它不像简单的数据库设计那么容易应用,但它仍然是这个问题的解决方案)。 我无法用MySQL使用的任何引擎或函数真正解决这个问题

所以我决定开发自己的软件来做它(C++中的,但是你可以把它应用到任何其他语言中)。 如果您要寻找的是一种在小字符串(my strings的平均长度为15)中搜索单词前缀的方法,那么您可以使用以下算法:

1. Create a trie. Each word of each string is put on the trie.
   Each leaf has a list of the ids that match that word.
2. Use a map/dictionary (or an array) to memorize the informations
   for each id (map[id] = information).
正在搜索字符串: 注意:字符串将以“Word1 Word2 Word3……”格式出现。如果它有一些符号,比如“γ”、“@”、“$”,则可以将它们视为“”(空格)。 例如:“拉斐尔·佩雷拉”

完成这些步骤后,您将拥有一个包含所有结果的集合。使用(视图,id)的对创建一个向量,并按降序对向量进行排序。因此,只需获得您想要的结果…我限制为30个结果

注意:您可以先对单词进行排序,以删除具有相同前缀的单词(例如,在“Jan Jan Ra”中,您只需要“Jan Ra”)。由于算法非常明显,因此我将不对此进行解释

这个算法有时可能不好(例如,如果我搜索“abcdef…z”,我会搜索整个trie…),所以我做了一个改进

1. For each "id" in your map, create also a small trie, that will
   contain the words of the string (include a trie for each m[id]...
   m[id].trie?).
然后,要进行搜索:

1. Choose the longest word in the search string (it's not guaranteed,
   but it is probably the word with the fewest results in the trie...).
2. Apply the step 1 of the old algorithm.
3. Make a vector with the ids in the mainSet.
4. Let's make the final vector. For each id in the vector you've created
   in step 3, search in the trie of this id (m[id].trie?) for all words
   in the search string. If it includes all words, it's a valid id and
   you might include it in the final vector; else, just ignore this id.
5. Repeat step 4 until there are no more ids to verify. After that, just
   sort the final vector for <views, id>.
1.选择搜索字符串中最长的单词(不保证,
但它可能是trie中结果最少的单词。
2.应用旧算法的步骤1。
3.使用主集中的ID创建一个向量。
4.让我们做最后一个向量。对于你创建的向量中的每个id
在步骤3中,在该id(m[id].trie?)的trie中搜索所有单词
在搜索字符串中。如果它包含所有单词,则它是一个有效的id,并且
您可以将其包含在最终向量中;否则,只需忽略此id即可。
5.重复步骤4,直到没有更多的ID需要验证。之后,只需
对最终向量进行排序。

现在,我使用数据库只是为了方便地存储和加载我的数据。此表中的所有查询都直接询问此软件。当我添加或删除记录时,我会将它们发送到数据库和软件,因此我总是保持更新。加载所有数据大约需要30秒,但查询速度很快(速度最慢的为0.03秒,平均为0.001s;使用我自己的笔记本电脑,没有在专用主机上尝试过,在专用主机上可能会快得多).

为了理解您的问题,为您的查询提供解释输出会很有帮助。返回的行数和索引的基数可能也会很有帮助。谢谢,但不再需要=D。问题是它与“+a*”匹配大约460000行。当我将其限制为10个结果时,这不再是问题,因为它只需要返回我的前10个结果。但是如果我要求MySQL按视图排序,它仍然需要得到所有460000个结果,排序,然后只返回我10个。如果不将它们全部排序=/,它无法知道这10个最好的结果是什么。我想使用MySQL是没有解决方案的。我已经搜索和研究了很多,试图做这些是的,但没有找到解决方案。
1. Choose the longest word in the search string (it's not guaranteed,
   but it is probably the word with the fewest results in the trie...).
2. Apply the step 1 of the old algorithm.
3. Make a vector with the ids in the mainSet.
4. Let's make the final vector. For each id in the vector you've created
   in step 3, search in the trie of this id (m[id].trie?) for all words
   in the search string. If it includes all words, it's a valid id and
   you might include it in the final vector; else, just ignore this id.
5. Repeat step 4 until there are no more ids to verify. After that, just
   sort the final vector for <views, id>.