我有一个我想要建立的查询,我想加入一些自然语言搜索。我不确定在mysql中做这件事的最佳方法。我相信mysql有一些很酷的自然语言的东西,我可以使用。
我有两张桌子,如下所示。
1. transaction_category...
+--------------------+--------------------+-------------------+----------+
| tran_category_code | tran_category_desc | tran_category_seq | btn_type |
+--------------------+--------------------+-------------------+----------+
| CarParking | Car Parking | 2 | default |
| Electricity | Electricity | 1 | default |
| Groceries | Groceries | 4 | default |
| HealthInsurance | Health Insurance | 5 | default |
| Other | Other | 7 | default |
| Petrol | Petrol | 3 | default |
| Phone | Phone | 6 | default |
+--------------------+--------------------+-------------------+----------+
2. transaction_category_keyword...
+---------------------------------+------------------------------+--------------------+
| transaction_category_keyword_id | transaction_category_keyword | tran_category_code |
+---------------------------------+------------------------------+--------------------+
| 6 | Telstra | Phone |
| 7 | Park | CarParking |
| 8 | Coles | Groceries |
| 9 | Bp Connect | Petrol |
| 10 | Bupa | HealthInsurance |
+---------------------------------+------------------------------+--------------------+
我的查询如下,返回我想要的结果,但我只是想知道是否有人能给我建议,是否可以使用mysql的自然语言功能来改进它。这会对我有帮助,因为现在的搜索非常简单,但我很快就会在它的基础上建立起来。
SELECT
tck.transaction_category_keyword_id,
tck.transaction_category_keyword,
tck.tran_category_code
FROM transaction_category tc, transaction_category_keyword tck
WHERE tc.tran_category_code = tck.tran_category_code
AND 'Coles Menai Syd Au' like '%' ||UPPER(tck.transaction_category_keyword) || '%'
+---------------------------------+------------------------------+--------------------+
| transaction_category_keyword_id | transaction_category_keyword | tran_category_code |
+---------------------------------+------------------------------+--------------------+
| 7 | Park | CarParking |
| 8 | Coles | Groceries |
| 10 | Bupa | HealthInsurance |
| 9 | Bp Connect | Petrol |
| 6 | Telstra | Phone |
+---------------------------------+------------------------------+--------------------+
谢谢
发布于 2014-08-12 06:00:16
通常,如果在搜索字段的开头和结尾都有通配符,那么对于任何非平凡的表大小,搜索都会相当缓慢,因为必须从每个索引开始搜索该字段。
您肯定会从全文搜索和匹配中受益,因为您正在搜索成袋的单词(以及它们在索引中的相对频率),而不是其他字段中的特定字符串。我想你已经读过http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html的文档了。有一些你需要理解的微妙之处,如停止词,布尔搜索,查询扩展等。这些页面上的评论非常好,因为它们已经积累了以前在那里做过实验的人的知识。
同样值得阅读的是tf-以色列国防军,这是MySQL (和许多其他全文搜索)内部的工作方式,参见文档,基本上是根据一个单词在所有文档中的稀有程度和某个特定文档中发生的次数的组合对搜索进行排序。
我不能给您提供更有重点的示例或性能度量,因为您的问题是,全文的性能会优于搜索这样的双通配符,对搜索的回答是几乎没有条件的是。
警告:考虑到引擎之间的差异,总是值得一提的,但是在MySQL版本5.6之前,全文搜索只用于MyISAM,但之后也使用InnoDB搜索。
https://stackoverflow.com/questions/25256973
复制相似问题