0

Sphinx cannot filter on strings, on integers.

I have some fields that are simple yes and no strings I would like to filter.

Is it possible to do a MySQL query something like this?

SELECT integer(FIELD:yes,1;no,2) AS sound FROM my_table;

Something like that? So that instead of yes, it gives me 1 and instead of no it gives me 2?

Then I would have as an attribute:

 sql_attr_unit = sound

and I could filter like so:

 $c->SetFilter(sound, array(1)); 

Does this look right?

CRAIG
  • 977
  • 2
  • 11
  • 25

1 Answers1

0

It appears that an If Else solution is what is needed to use from this post:

How do write IF ELSE statement in a MySQL query

 SELECT (case when (Sound = 'yes') then 1 else 0 end) AS Sound FROM my_table;

This appears to be the solution for yes and no items.

Community
  • 1
  • 1
CRAIG
  • 977
  • 2
  • 11
  • 25
  • 1
    Just a reference a short hand syntax: `SELECT IF(Sound='yes',1,0) AS Sound FROM ...` – barryhunter Aug 28 '14 at 11:55
  • @barryhunter I was actually hoping you would comment on this. It doesn't seem to be working for me. Can you check my modifications above and verify that it *should* work based on that so I can at least know it *should* work? Thanks!! – CRAIG Aug 28 '14 at 18:16
  • 1
    For a real live and working example, http://svn.geograph.org.uk/svn/branches/british-isles/system/sphinxserver/usr/local/etc/sphinx.conf (search for 'prefered') – barryhunter Aug 28 '14 at 21:03
  • That's a great example @barryhunter. Thanks for sharing that. I think it will prove very useful. – CRAIG Aug 28 '14 at 22:12