Searching Multiple Columns

2 views
Skip to first unread message

Will Clark

unread,
Nov 23, 2009, 3:55:59 PM11/23/09
to Thinking Sphinx
I need to search for users where the end user will submit separate
values for name, city, email, and keyword, which would be compared
against users.name, users.city, users.email, users.description.

At first, I thought I'd be able to use sphinx_scope like this:

sphinx_scope(:first_name_like) { |first_name| { :conditions =>
["first_name ILIKE ?","%#{first_name}%"] } }

But that won't work. How would you go about doing something like that,
or is this a situation where ThinkingSphinx/Sphinx is not the right
tool for the job.

Pat Allan

unread,
Nov 25, 2009, 12:08:42 AM11/25/09
to thinkin...@googlegroups.com
Hi Will

You're using SQL syntax in your sphinx_scope, which Sphinx (and
Thinking Sphinx) won't understand.

However, the following should do the job:

sphinx_scope(:first_name_like) { |first_name|
{:conditions => {:first_name => "*#{first_name}*"}}
}

This will require you to have wildcard syntax set up, though. See
about halfway down this page:
http://freelancing-god.github.com/ts/en/advanced_config.html

Cheers

--
Pat
> --
>
> You received this message because you are subscribed to the Google
> Groups "Thinking Sphinx" group.
> 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=
> .
>
>

Reply all
Reply to author
Forward
0 new messages