MySQL 5.6 Full Text Search Issue when Searching for the word “the” in PHP

♀尐吖头ヾ 提交于 2019-12-10 22:25:47

问题


Im having an issue when my search includes the word "the" in my full text search.

Here is my search code with the problem:

SELECT * FROM names WHERE MATCH(myname) AGAINST ('+the' IN BOOLEAN MODE)

This one works fine:

SELECT * FROM names WHERE MATCH(myname) AGAINST ('+and' IN BOOLEAN MODE)

I already turned off the stop words in my CNF file, changed the min letters to 3 using both ft_min_word_len=3 AND innodb_ft_min_token_size=3

I'm using innodb. And returns 27000 results and 'the' returns 17000 from a db of about 500,000 records so im not hitting the 50% mark, even so, I'm using boolean mode. I can't find another word that breaks this. Any ideas?


回答1:


Ok, I finally figured this out. It looks like I already had the myisam stopwords cleared but not the innodb ones. It's a little but harder to do than for myisam but here are the steps for anyone else that might need it:

In your /etc/my.cnf (or my.ini on windows) add these lines:

Create a stopwords table. I made mine in a db called settings and a table called innodb-stopwords. You cannot just set innodb_ft_enable_stopword = 0, you have to create and link to a table.

Make sure your table is innodb and add a column called value, varchar(?), utf8_general_ci. You can leave it empty or add values to the table.

innodb_ft_enable_stopword = 1  
innodb_ft_server_stopword_table = settings/innodb-stopwords

Restart your mysql server.

Drop and recreate your fulltext indexes.

If you don't want to restart the server, you can dynamically set the variables with (also update the cnf/ini file for the next server restart)

--innodb_ft_enable_stopword=1
--innodb_ft_server_stopword_table=db_name/table_name

I don't see any workaround to recreating the index... you can do it in one command though so the table is locked the whole time and your users don't get errors:

ALTER TABLE `tablename` DROP INDEX indexname, ADD FULLTEXT(`columnname`);



回答2:


Build a different stop-word list. Remove "the" and "and" from it.



来源:https://stackoverflow.com/questions/33420702/mysql-5-6-full-text-search-issue-when-searching-for-the-word-the-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!