Francis Lewis
Francis Lewis

Reputation: 8980

Getting a minimum number of results from fulltext search

I have a text field that I'm searching against using an array of keywords and right now, I'm either searching for all of the keywords or any of the keywords.

My question is: is there a way to pull results with a minimum number of keywords? For example, I'm searching for 6 keywords, but I only need 50% of them to match, so I want the fulltext search to only return results that have matched at least 3 of the keywords.

Is this even possible? Maybe by using a FullText Modifier?

Upvotes: 0

Views: 132

Answers (1)

Highway of Life
Highway of Life

Reputation: 24411

When you do a fulltext search using the IN BOOLEAN MODE modifier in your select statement, it can display the number of matches in the search. Example:

SELECT id, MATCH (text) AGAINST ('MySQL Fulltext' IN BOOLEAN MODE) AS matches
FROM table_name
HAVING matches > 2;

Upvotes: 2

Related Questions