oz11 Posted February 6 Share Posted February 6 (edited) Hi. How would i go about adding a WHERE clause to this query... SELECT *, l.link_id , l.url , l.title , t.term , d.content , d.link_id , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t')) as `rank` FROM links l JOIN terms t ON l.link_id = t.link_id JOIN links_description d ON d.link_id = l.link_id WHERE MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) OR MATCH(url, title) AGAINST('w00t') OR MATCH(content) AGAINST('w00t') GROUP BY title ORDER BY `rank` DESC LIMIT 200; Ive tried the following, but it doesn't work, SELECT *, l.link_id , l.url , l.title , t.term , l.content_type , d.content , d.link_id , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t')) as `rank` FROM links l JOIN terms t ON l.link_id = t.link_id JOIN links_description d ON d.link_id = l.link_id WHERE MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) OR MATCH(url, title) AGAINST('w00t') OR MATCH(content) AGAINST('w00t') AND MATCH(l.content_type) AGAINST('docume') // <----------------------- GROUP BY title ORDER BY `rank` DESC LIMIT 200; Does not filter the results at all, based on content_type. Edited February 6 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/317703-adding-a-where-clause-to-query/ Share on other sites More sharing options...
gizmola Posted February 6 Share Posted February 6 Is content_type a fulltext indexed field? I'm guessing it isn't. So you would just do .. AND l.content_type = 'docume' 1 Quote Link to comment https://forums.phpfreaks.com/topic/317703-adding-a-where-clause-to-query/#findComment-1614771 Share on other sites More sharing options...
Solution gizmola Posted February 6 Solution Share Posted February 6 It also looks like you want to group the prior fulltext searches, so something like this? SELECT *, l.link_id , l.url , l.title , t.term , l.content_type , d.content , d.link_id , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t')) as `rank` FROM links l JOIN terms t ON l.link_id = t.link_id JOIN links_description d ON d.link_id = l.link_id WHERE (MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) OR MATCH(url, title) AGAINST('w00t') OR MATCH(content) AGAINST('w00t')) AND l.content_type = 'docume') GROUP BY title ORDER BY `rank` DESC LIMIT 200; 1 Quote Link to comment https://forums.phpfreaks.com/topic/317703-adding-a-where-clause-to-query/#findComment-1614772 Share on other sites More sharing options...
oz11 Posted February 6 Author Share Posted February 6 Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/317703-adding-a-where-clause-to-query/#findComment-1614774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.