filter on a merged column

18 views
Skip to first unread message

Mark

unread,
Feb 23, 2009, 2:24:45 AM2/23/09
to Thinking Sphinx
Hi,

I'm trying to filter on a merged location column. The index has the
definition:

has [:city, :state], :as => :location

I'm trying to filter on with[:location] = 'San Francisco CA'.

I've tried to do this a ton of different ways, but it never works.
Can somebody post an example of the correct way to filter on a merged
column?

Thanks

Pat Allan

unread,
Feb 23, 2009, 8:27:14 AM2/23/09
to thinkin...@googlegroups.com
Hi Mark

At this point, Thinking Sphinx doesn't support filtering on string
attributes (because Sphinx doesn't either). I've had a patch submitted
that offers a workaround for this, but in the meantime, I'd switch
location to being a field, and using the :conditions hash instead.

indexes [city, state], :as => :location

Model.search :conditions => {:location => "San Francisco CA"}

Cheers

--
Pat

Mark

unread,
Feb 23, 2009, 1:18:00 PM2/23/09
to Thinking Sphinx
Thanks Pat,

I realized that I slightly mis-typed my original question. What I
actually want to do is a

without[:location] = 'San Francisco CA'

Can that be done in the conditions statement as well?

Mark

unread,
Feb 23, 2009, 3:11:53 PM2/23/09
to Thinking Sphinx
I actually got this working with a negated query, but the strange this
is that it only works if a search term is also specified. For
example:

Job.search 'keyword', :conditions => {:location => '-"San Francisco
CA"'}

This query correctly returns job entries that match "keyword" but are
not in San Francisco.

Job.search :conditions => {:location => '-"San Francisco CA"'}

This query doesn't return anything, although I was hoping it would
return all job entries not in San Francisco.

Any ideas why that doesn't work, and what I can do then to execute an
"all jobs not in San Francisco" query?

Thanks

Mark

unread,
Feb 23, 2009, 5:28:17 PM2/23/09
to Thinking Sphinx
Here's what the sphinx log is showing, which doesn't make any sense to
me. I can't figure out why the less restrictive search is not
returning any results.

[Mon Feb 23 14:26:21.671 2009] 0.001 sec [ext/3/rel 1 (0,15)] [*]
testing @location !"San Francisco CA"

[Mon Feb 23 14:24:07.953 2009] 0.001 sec [ext/3/rel 0 (0,15)] [*]
@location !"San Francisco CA"

Pat Allan

unread,
Mar 3, 2009, 3:01:41 AM3/3/09
to thinkin...@googlegroups.com
Hi Mark

This seems to be a bug in Sphinx as far as I can tell (happens with
the command line tool as well as Thinking Sphinx/Riddle). I'm not sure
if there's cleaner solutions out there, but something that I just
described for another email on this list is to add a manual field so
there's a word that appears in every result:

indexes "'sphinxisbuggy'", :as => :catch_all
# ...
Job.search "sphinxisbuggy", :conditions => {:location => '-"San
Francisco CA"'}

Sorry I can't be more helpful.

--
Pat
Reply all
Reply to author
Forward
0 new messages