Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exact word matches with different combinations from given query string in mysql full-text search

how to make myisam table to return results that are matching with different combination of words and nothing more extra from given search string.

I am using the following query on my tags table

SELECT * FROM tags WHERE MATCH (name) AGAINST('word1 word2'));

and the table might contain rows as follows

  • 1 word1 word2 word3
  • 2 word2 word3 word4
  • 3 word1
  • 4 word3 word2
  • 5 word2
  • 6 word2 word1
  • 7 word1 word2
  • 8 word3 word4

i need only the following rows as results

  • 3 word1
  • 5 word2
  • 6 word2 word1
  • 7 word1 word2

but the actual result i am getting is

  • 1 word1 word2 word3
  • 2 word2 word3 word4
  • 3 word1
  • 4 word3 word2
  • 5 word2
  • 6 word2 word1
  • 7 word1 word2

how to achieve this??

I have tried boolean mode search with + but it makes that the words given + as compulsory in search results which is not what i want.

like image 881
Anil Kumar Avatar asked Dec 09 '25 06:12

Anil Kumar


1 Answers

This may be a late reply, yet, this will solve the issue. Use IN BOOLEAN MODE of MySQL FTS.

SELECT * FROM `tags` WHERE MATCH (`name`) AGAINST('+word1 +word2' IN BOOLEAN MODE)

Take a look at Full Text Boolean Mode

Note In implementing this feature, MySQL uses what is sometimes referred to as implied Boolean logic, in which

+ stands for AND

- stands for NOT

[no operator] implies OR

like image 189
Vinothkumar Arputharaj Avatar answered Dec 11 '25 01:12

Vinothkumar Arputharaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!