你如何得到你的Fulltext布尔搜索来取代这个术语C ++? [英] How do you get your Fulltext boolean search to pick up the term C++?

查看:144
本文介绍了你如何得到你的Fulltext布尔搜索来取代这个术语C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我需要了解如何在MySQL数据库上进行全文检索,以返回包含术语C ++的记录。



我有我的SQL搜索字符串为:

  SELECT * 
FROM mytable
WHERE MATCH(field1,field2,field3)
AGAINST(C ++IN BOOLEAN MODE)

尽管我的所有字段都包含字符串C ++,它从来没有在搜索结果中返回。



如何修改MySQL以适应这一点?可能吗?



我发现的唯一解决方案是在输入我的数据的过程中转义+字符,如__plus,然后修改我的搜索以适应,但是这似乎很麻烦,必须有一个更好的方法。

解决方案


如何修改MySQL以适应这一点?


您将不得不更改MySQL对某个字词的想法。



首先,默认的最小字长是4.这意味着,不包含<4个字母的单词的搜索字词将永远匹配,无论是C ++还是cpp。您可以使用 ft_min_word_len 进行配置配置选项,例如。在您的my.cfg中:

  [mysqld] 
ft_min_word_len = 3

(然后停止/启动MySQLd并重建全文索引。)



其次,'+ 不认为是MySQL的一封信。你可以写一封信,但这意味着你将无法在字符串鱼+芯片中搜索鱼一词,因此需要注意。这不是微不足道的:它需要重新编译MySQL或黑客现有的字符集。请参阅第11.8.6节


在+将数据输入__plus的过程,然后修改我的搜索以适应


是的,这样的东西是常见的解决方案:您可以在主要的最终表中保持您的真实数据(无转义) - 通常使用InnoDB来遵守ACID。然后可以添加一个辅助MyISAM表,只包含全文搜索诱饵的文件。您也可以使用这种方法做一个限制形式的干扰。



另一种可能性是检测MySQL不能做的搜索,例如只有短字的搜索,或不寻常的字符,并回到简单但缓慢的LIKE或REGEXP仅搜索这些搜索。在这种情况下,您可能还需要通过设置 ft_stopword_file 到一个空字符串,因为它是不切实际的接收一切特别的。


So, I need to find out how to do a fulltext boolean search on a MySQL database to return a record containg the term "C++".

I have my SQL search string as:

SELECT * 
FROM mytable 
WHERE MATCH (field1, field2, field3) 
AGAINST ("C++" IN BOOLEAN MODE) 

Although all of my fields contain the string C++, it is never returned in the search results.

How can I modify MySQL to accommodate this? Is it possible?

The only solution I have found would be to escape the + character during the process of entering my data as something like "__plus" and then modifying my search to accomodate, but this seems cumbersome and there has to be a better way.

解决方案

How can I modify MySQL to accommodate this?

You'll have to change MySQL's idea of what a word is.

Firstly, the default minimum word length is 4. This means that no search term containing only words of <4 letters will ever match, whether that's ‘C++’ or ‘cpp’. You can configure this using the ft_min_word_len config option, eg. in your my.cfg:

[mysqld]
ft_min_word_len=3

(Then stop/start MySQLd and rebuild fulltext indices.)

Secondly, ‘+’ is not considered a letter by MySQL. You can make it a letter, but then that means you won't be able to search for the word ‘fish’ in the string ‘fish+chips’, so some care is required. And it's not trivial: it requires recompiling MySQL or hacking an existing character set. See the section beginning "If you want to change the set of characters that are considered word characters..." in section 11.8.6 of the doc.

escape the + character during the process of entering my data as something like "__plus" and then modifying my search to accomodate

Yes, something like that is a common solution: you can keep your ‘real’ data (without the escaping) in a primary, definitive table — usually using InnoDB for ACID compliance. Then an auxiliary MyISAM table can be added, containing only the mangled words for fulltext search bait. You can also do a limited form of stemming using this approach.

Another possibility is to detect searches that MySQL can't do, such as those with only short words, or unusual characters, and fall back to a simple-but-slow LIKE or REGEXP search for those searches only. In this case you will probably also want to remove the stoplist by setting ft_stopword_file to an empty string, since it's not practical to pick up everything in that as special too.

这篇关于你如何得到你的Fulltext布尔搜索来取代这个术语C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆