2017-05-01 99 views
0

是否可以像OR條件那樣做AND條件?思維與獅身人面像中的AND和OR條件

這是我簡單的獅身人面像的查詢只AND ...

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 

我想補充的或者......像......

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

這樣我就可以搜索不同canonical_type的ID。

不知道如何去思考獅身人面像。

謝謝!

回答

0

這是獅身人面像本身的限制。它不支持OR中的WHERE(也不嵌套) - 這就是爲什麼它不在思考sphinx。

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

可以寫成SphinxQL:

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

...即()運算符是有點像 '或'。如果thinkinx - 獅身人面像基於http://freelancing-gods.com/thinking-sphinx/searching.html#filters

一個陣列

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

自動執行它也不會感到驚訝