RaGu
RaGu

Reputation: 693

How to make conditions with CASE WHEN in SphinxQL?

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

Answers (1)

barryhunter
barryhunter

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

Related Questions