本文介绍了你如何让你的全文布尔搜索拿起术语C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我需要找出如何做一个MySQL数据库上全文布尔搜索返回的记录containg术语C ++。

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

  SELECT *
FROM MYTABLE
WHERE MATCH(字段1,场2,FIELD3)
AGAINST(C ++IN BOOLEAN MODE)

虽然我所有的字段包含字符串C ++,这是从来没有在搜索结果中返回。

我如何修改MySQL来适应呢?是否可以?

我发现会进入我的数据,像__plus,然后修改我的搜索,以适应过程中为了躲避+字符,但这似乎麻烦,必须有一个更好的办法,唯一的解决办法。


解决方案

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.

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.

这篇关于你如何让你的全文布尔搜索拿起术语C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:44