Jump to content

Using MATCH (...) AGAINST (...) with UNIONs!?


spiceydog

Recommended Posts

i need to MATCH () AGAINST... my entire query not just each seperate UNION... what do i do?

 

This is a search query I am working with so here is the mysql_query:

(SELECT * FROM albuminfo WHERE albumname LIKE '%$searchs%' GROUP BY albumname ORDER 
BY views LIMIT 10) UNION (SELECT * FROM albuminfo WHERE artist LIKE '%$searchs%' GROUP BY
albumname ORDER BY views LIMIT 10) UNION (SELECT * FROM albuminfo WHERE track LIKE '%$searchs
%' GROUP BY albumname ORDER BY views LIMIT 10) UNION (SELECT * FROM albuminfo WHERE 
keywords LIKE '%$searchs%' GROUP BY albumname ORDER BY views LIMIT 10) UNION (SELECT * FROM 
albuminfo WHERE user LIKE '%$searchs%' GROUP BY albumname ORDER BY views LIMIT 10) MATCH 
($where) AGAINST ('$sarray' IN BOOLEAN MODE) LIMIT 0, 10

 

$searchs (which is an array) = Array ( [0] => korn [1] => leader [2] => follow [3] => the )
$sarray = +korn +leader +follow +the
$where = user, albumname, artist, keywords, track

 

The error message i am getting is this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server 
version for the right syntax to use near 'MATCH (user, albumname, artist, keywords, track) AGAINST ('+korn +leader +follow' at line 1

 

What do i do?

Link to comment
https://forums.phpfreaks.com/topic/119616-using-match-against-with-unions/
Share on other sites

  SELECT * FROM albuminfo
    WHERE MATCH (user,albumname,artist,keywords,track) AGAINST ('$sarray' IN BOOLEAN MODE);

 

Also while you're using the operator + for the words in your input array means mysql is looking for records that match ALL the words.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.