简体   繁体   中英

PHP/MySQL: match / against escaping stopword

Here's my query:

SELECT * from description WHERE (match(description) AGAINST ( '+will +smith' in boolean mode)) 

I'm aware that will is a stopword that's why i'm getting an empty result. How would it work that i can still use both words for this query? Do i need to escape it in somekind of way?

There isn't a way to "escape" a stopword for a given search. Think of it this way: when creating the fulltext index, it skips indexing words if they are stopwords. That is, the words are not stored in the fulltext index. So you can't subsequently escape the word in a given search and have a word magically appear in the fulltext index since that wasn't included when the index was created.

Assuming you are using fulltext search with InnoDB, the solution is apparently to define your own table storing stopwords. Then you can put a customized set of words into the table, and use the configuration variable innodb_ft_server_stopword_table to make your instance of MySQL use your custom table before creating your fulltext index. This way, the word you want to be indexed will be included as it builds the fulltext index.

Seehttps://dev.mysql.com/doc/refman/8.0/en/fulltext-stopwords.html

But this is a global variable, so it will affect all fulltext index creation on all tables on that MySQL instance. I suppose you could set the innodb_ft_server_stopword_table to your custom table, build your fulltext index, and then set the option back to its usual value. But that would be tricky, because anytime you rebuild your fulltext index (for instance during an alter table or optimize table), it would revert to the default stopwords.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM