Josh wrote:
> I've always passed my fields and attributes to search with the
> conditions option, like this:
>
> Model.search(:conditions => {:string => 'foo', :attribute => 1})
>
> I now need to do some "or" searches, and it appears that the way to do
> this is by converting this to a query string. This works fine when
> dealing exclusively with a string field:
>
> Model.search("(@string foo | @string bar)")
>
> But it appears that I can't pass attributes in the same way. For
> example, these searches will always return no results:
>
> Model.search("@attribute 1")
> Model.search("@string foo @attribute 1)")
> Model.search("(@string foo | @string bar) @attribute 1")
Unfortunately, this is how sphinx works. The field conditions are built
into a query string but the attributes are passed to the daemon as
filters using a different part of the API. This means the filters can't
be included in the logic of the query string, regardless of he
> These search examples could be handled by passing the attribute
> using :conditions or :with. But what I'm still stuck on is how to
> accomplish this:
>
> Model.search("(@string foo | @attribute 1)")
>
> As far as I can tell, this isn't possible. Any chance someone has
> found a solution for this?
Pat may correct me, but I'm pretty sure filters don't allow OR
conditions.
My (somewhat limited) workaround is to define a new attribute that has
the OR defined in SQL:
has "IF(active = 1 OR in_stock > 0, 1, 0)", :as => :available, :type =>
:boolean
-- James Healy <jimmy-at-deefa-dot-com> Tue, 21 Jul 2009 22:32:58 +1000
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---