Skip to content
Advertisement

How can I use a FULLTEXT query with MySQL to return all results matching a string?

This is the table videos: enter image description here

I currently have this query:

SELECT *, COUNT(history.v_id) AS videoCheck, MATCH (v_title, v_desc, v_tags) AGAINST ("%not%") AS relevance FROM videos LEFT JOIN history ON history.v_id = videos.v_id WHERE MATCH (v_title, v_desc, v_tags) AGAINST ("%not%") GROUP BY relevance DESC

I want that query to return all results with the string not in it but it is only returning 1 result instead of 2.

What is the best way to get it to return all matching queries instead of only 1?


Edit1:

If I use the WITH QUERY EXPANSION modifier it does return 2 results but that is still not what I want because if the string changes to for example asd it also only returns 2 results instead the many more which are stored.

Edit2:

Query with LIKE:

SELECT *, COUNT(history.v_id) AS videoCheck FROM videos LEFT JOIN history ON history.v_id = videos.v_id WHERE CONCAT_WS(v_tags, v_title, v_desc) LIKE :input GROUP BY history.v_id ORDER BY videoCheck DESC

Advertisement

Answer

This query seems to be doing what I want:

SELECT *, MATCH (v_title, v_desc, v_tags) AGAINST (:input) AS relevance  FROM videos WHERE MATCH (v_title, v_desc, v_tags) AGAINST (:inputWhere) ORDER BY relevance DESC

I don’t need the LEFT JOIN any more as I am no longer ordering by videoCheck.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement