1
votes

Is it possible to do something like an AND condition with OR?

This is my simple sphinx query with AND only...

Job.search('', {with: {canonical_type: Zlib::crc32('SubCategory')},  conditions: { sub_category_ids: [4]}})

Sphinx Query (22.8ms)  SELECT * FROM `job_core`, `job_delta` WHERE MATCH('@sub_category_ids [4]') AND `canonical_type` = 1916160457 AND `sphinx_deleted` = 0 LIMIT 0, 20 OPTION max_matches=50000
  Sphinx  Found 1 results

I'd like to add an OR... something like...

WHERE (MATCH('@sub_category_ids [4]') AND `canonical_type` = 1916160457 OR MATCH('@sub_category_ids [4]') AND `canonical_type` = 4282022807)

so that I can search for IDs with different canonical_type.

Not sure how to do it in Thinking Sphinx.

Thanks!

1

1 Answers

1
votes

This is actully a limitation of Sphinx itself. It doesnt support OR in WHERE (nor nesting) - which is why it not in thinking-sphinx.

But

WHERE (MATCH('@sub_category_ids [4]') AND `canonical_type` = 1916160457 
    OR MATCH('@sub_category_ids [4]') AND `canonical_type` = 4282022807)

could be written as SphinxQL:

WHERE MATCH('@sub_category_ids [4]') AND `canonical_type` IN (1916160457,4282022807)

... ie IN() operator is kinda like 'OR'. Wouldn't be surprised if thinkinx-sphinx does it automatically with a array

with: {canonical_type: [Zlib::crc32('SubCategory1'), Zlib::crc32('SubCategory2')] }

based on http://freelancing-gods.com/thinking-sphinx/searching.html#filters