Help with OR Logic with Attribute Filters

96 views
Skip to first unread message

Sabarish Sankar

unread,
Feb 29, 2012, 12:06:22 PM2/29/12
to thinkin...@googlegroups.com, mrud...@chronus.com
Hi,

I have a use case where I need to use OR logic with attribute filters. Here is the scenario, User has many roles and has an attribute called global. Below is the index block

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

And I need to get users with have roles with id 5 or the users  with global true. Here is the query I am trying to use

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

This results in a syntax error -  unexpected TOK_ATTR_MVA near 'role_ids = 5, 1, 0)' . The problem here seems to be that role_ids is a MVA.

Any help?

Thank you,
Sabarish

Pat Allan

unread,
Feb 29, 2012, 6:26:18 PM2/29/12
to thinkin...@googlegroups.com

Hi Sabarish

I think you'll need to use the IN function for MVAs:
http://sphinxsearch.com/docs/manual-2.0.1.html#expr-func-in

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

Cheers

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/id94c3zziyYJ.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.


Sabarish Sankar

unread,
Mar 1, 2012, 2:12:42 AM3/1/12
to thinkin...@googlegroups.com
Thanks a lot Pat! That helped us.


On Thursday, March 1, 2012 4:56:18 AM UTC+5:30, pat wrote:

Hi Sabarish

I think you'll need to use the IN function for MVAs:
http://sphinxsearch.com/docs/manual-2.0.1.html#expr-func-in

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

Cheers

--
Pat

On 01/03/2012, at 4:06 AM, Sabarish Sankar wrote:

> Hi,
>
> I have a use case where I need to use OR logic with attribute filters. Here is the scenario, User has many roles and has an attribute called global. Below is the index block
>
> define_index do
>   has roles(:id), :as => :role_ids
>   has global
> end
>
> And I need to get users with have roles with id 5 or the users  with global true. Here is the query I am trying to use
>
> User.search(:sphinx_select => "*, IF(global OR role_ids = 5, 1, 0) AS program_global", :with => {'program_global' => true})
>
> This results in a syntax error -  unexpected TOK_ATTR_MVA near 'role_ids = 5, 1, 0)' . The problem here seems to be that role_ids is a MVA.
>
> Any help?
>
> Thank you,
> Sabarish
>
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/id94c3zziyYJ.

> To post to this group, send email to thinking-sphinx@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphinx+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages