Reputation: 693
How can I set condition for Sphinx search? In my custom MySQL code, which is as followed.
How can I re-code it as Sphinx search?
$condition = "(CASE WHEN related_type ='Course' THEN related_id = 1
ELSE related_id IN(2,3,4)
END)";
Upvotes: 0
Views: 917
Reputation: 21091
SphinxQL has an IF()
function that can be used in similar fashion.
For example:
SELECT *, IF(related_type='Course', related_id=1, IN(related_id, 2,3,4) ) AS filter
FROM myindex WHERE filter = 1
Functions need to be in the SELECT
part, not in WHERE
(also note the slightly different syntax for IN()
. In sphinx it's a function)
Upvotes: 1