0

I have a table in a database with records containing keywords as well as other data. What would be a logical way to create a search function that would allow people to search based on keywords, and order results based on the number of matched keywords?

bluish
  • 26,356
  • 27
  • 122
  • 180
RobM
  • 246
  • 2
  • 4
  • 12

2 Answers2

2

Mysql provide FULLTEXT search options. Check this link mysql full text search. These search results will be sorted according to best match. it also has support for boolean mode and NATURAL LANGUAGE MODE(default). You need to add FULLTEXT index on search column.

Uday Sawant
  • 5,748
  • 3
  • 32
  • 45
1

Here is the query that will work for you.

SELECT *, MATCH (ab,cd) AGAINST ('sample text' IN BOOLEAN MODE) AS relevancy 
FROM table_name 
WHERE MATCH (ab,cd) AGAINST ('sample text' IN BOOLEAN MODE) 
ORDER BY relevancy DESC;
bluish
  • 26,356
  • 27
  • 122
  • 180
er.miteshp
  • 75
  • 2
  • 11