yuli chika
yuli chika

Reputation: 9221

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)

Upvotes: 4

Views: 492

Answers (2)

HorusKol
HorusKol

Reputation: 8696

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.

Upvotes: 1

Charles
Charles

Reputation: 51411

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.

Upvotes: 2

Related Questions