或Sphinx中的属性过滤器逻辑

时间:2012-02-29 17:17:13

标签: ruby-on-rails sphinx thinking-sphinx

我有一个用例,我需要在属性过滤器中使用OR逻辑。这是场景,用户有很多角色,并且有一个名为global的属性。下面是索引块

define_index do
  has roles(:id), :as => :role_ids
  has global
end

我需要让拥有id为5的用户或拥有全局true的用户。这是我试图使用的查询

User.search(
     :sphinx_select => "*, IF(global OR role_ids = 5, 1, 0) AS program_global",
     :with => {'program_global' => true},
     :match_mode => :extended
)

这会导致语法错误 - 'role_ids = 5,1,0'附近意外的TOK_ATTR_MVA'。这里的问题似乎是role_ids是一个MVA。我正在使用sphinx 0.9.9

任何帮助?

1 个答案:

答案 0 :(得分:2)

这是Pat提供的答案

https://groups.google.com/forum/?fromgroups#!topic/thinking-sphinx/kxNIGP10hkQ

"*, IF(global OR IN(role_ids, 5), 1, 0) AS program_global"