fredley
fredley

Reputation: 33901

Space in MySQL search

My query is formulated thus:

$sql = "SELECT name, id FROM table WHERE MATCH (name) AGAINST ('".$query."*' IN BOOLEAN MODE) LIMIT 0,10";

So searching for tom retrieves:

Tom Anderson   |   1
Tom Bennet     |   2
Tom Cane       |   3

However, if I search for tom anderson the query compiles to:

 ...MATCH (name) AGAINST ('tom anderson*' IN BOOLEAN MODE)...

Which returns the same set of results (I only want the first). How should I change my query?

Upvotes: 0

Views: 686

Answers (1)

Nanne
Nanne

Reputation: 64409

You should either use a + to indicate a word must be present, or use " to indicate a complete frase

Check the boolean mode manual

I guess this'll work

 ...MATCH (name) AGAINST ('"tom anderson"*' IN BOOLEAN MODE)...

Upvotes: 1

Related Questions