简体   繁体   中英

PHP MYSQL FULLTEXT how to make a Precise search?

I make a PHP MYSQL FULLTEXT search, but how to make a Precise search? As I use some following code, I need return the data which must contain word 'new' and 'york', em... in fact the code will return some data only contain 'new' but never has 'york'. So how?

SELECT * FROM text WHERE MATCH (title,body) AGAINST('new+york' IN BOOLEAN MODE)

You've stumbled upon an edge case -- the problem isn't what you think it is.

MySQL fulltext indexing by default will not index words under four characters in length, like "new" . If you want to search for "new" , then you'll need to adjust the minimum word length and rebuild your indexes.

Although Charles is correct regarding the length of the word 'new', there is another issue here - even reindexing with a shorter minimum word length (not entirely advisable), you will get content that contains the word 'new' and 'york' and many words in between them, but not necessarily just the string 'new york'.

Also, there's a good chance that the word 'new' is in more then 50% of your records, so no records will return for that.

I came up with a way of incorporating exact string matching with fulltext indexes a couple of years ago - though I never got around to including boolean mode searches as well.

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