Hi Elías

You're missing a space when you join the two sets of data together in your 
search query
  current_account.interests + ' ' + current_account.tags

That said, you *can* search across different fields with OR logic, it's just 
that you can't do it using :conditions...

Quick overview: :conditions => {:foo => 'bar'} gets translated to '@foo bar' 
for Sphinx. So, if you construct the query yourself, you probably want the 
following:

  (@tags #{ current_account.tags.split(/\s+/).join(' | ') }) | (@interests #{ 
current_account.integers.split(/\s+/).join(' | ') })

Might be more elegant ways of building that, but you want to put that in as the 
main query string, and then set the match mode explicitly (because you're not 
using :conditions any more):

  Account.search query, :match_mode => :extended, :star => true

-- 
Pat

On 11/03/2010, at 4:43 PM, elioncho wrote:

> As I explained above, I needed a way to specify OR conditions to
> search by tags or interests. I've read a few things here and there and
> found out that is not possible (maybe I missed something). So, I
> decided to make an index with both fields as shown below, but this
> ain't working at all. What am I doing wrong?
> 
> define_index do
>  indexes [tags, interests], :as => :foo
>  indexes :about
>  ...
> end
> 
> The search:
> 
> @accounts = Account.search :conditions => {:foo =>
> (current_account.interests+current_account.tags).split(/\s+/).join(' |
> ')  }, :star => true
> 
> On Mar 10, 10:23 pm, elioncho <[email protected]> wrote:
>> Thanks Pat,
>> 
>> One last thing. Is there a way to add some OR conditions in
>> the :conditions hash or is this not possible? Is there is another way
>> to add this OR functionality? I haven't found anything so far.
>> 
>> Thanks a lot,
>> 
>> Elías
>> 
>> On Mar 10, 6:36 pm, Pat Allan <[email protected]> wrote:
>> 
>>> Ah, I didn't realise you were searching on a specific field - that requires 
>>> (and automatically sets) the match mode to :extended.
>> 
>>> But, you can use boolean logic in extended mode. What you'll need to do is 
>>> split your tags with |'s ie:
>>>   "stores | markets | finance"
>> 
>>> So, perhaps this snippet this will help:
>>>   current_account.interests.split(/\s+/).join(' | ')
>> 
>>> Cheers
>> 
>>> --
>>> Pat
>> 
>>> On 11/03/2010, at 10:15 AM, elioncho wrote:
>> 
>>>> Thank you Pat, but I still have a problem. I'm indexing two fields in
>>>> my account model (tags and interests). This fields are fill in by the
>>>> user when he creates his account. My app has to show each account
>>>> which others accounts may interest him. So the app takes the arguments
>>>> on the interests field and searches on the other accounts tags field.
>> 
>>>> @accounts = Account.search :conditions => {:tags =>
>>>> current_account.interests }, :star => true, :match_mode => :any
>> 
>>>> The problem is that :conditions doesn't works with :match_mode
>>>> => :any, only :extended. So if the user has as interests (books,
>>>> papers, pencils) and there is an account with tags (papers, pencils)
>>>> the search doesn't gives me any results. How can I get around this
>>>> issue?
>> 
>>>> Thank you!
>> 
>>>> On Mar 4, 12:40 am, Pat Allan <[email protected]> wrote:
>>>>> HiElioncho
>> 
>>>>> It sounds like you want to match ANY of the words, instead of ALL the 
>>>>> words. Sphinx (and Thinking Sphinx) default to ALL - but you can choose 
>>>>> other match modes if you'd like, including ANY:
>> 
>>>>>   Model.search "stores markets finance", :match_mode => :any
>> 
>>>>> The docs have a bit more information on 
>>>>> this:http://freelancing-god.github.com/ts/en/searching.html#matchmodes
>> 
>>>>> Cheers
>> 
>>>>> --
>>>>> Pat
>> 
>>>>> On 02/03/2010, at 1:55 PM,elionchowrote:
>> 
>>>>>> Hi guys,
>> 
>>>>>> When I query for 'stores, markets, finance' and I have on my indexes
>>>>>> columns two rows of data with:
>> 
>>>>>> - stores
>>>>>> - shirts, pants, lotions, stores
>> 
>>>>>> (see 'stores' is in both)
>> 
>>>>>> I expect to get these two rows of data as results, but I don't get
>>>>>> anything. The only way to get this two rows of data is by only
>>>>>> querying for 'stores'. Now I wonder, how can I configure thinking
>>>>>> sphinx to fetch for me these two rows of data?
>> 
>>>>>> Thank you,
>> 
>>>>>> Elioncho
>> 
>>>>>> --
>>>>>> 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 
>>>>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
>> 
>>>> --
>>>> 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 
>>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
> 
> -- 
> 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.
> 

-- 
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.

Reply via email to