Riddle, SPH_SORT_EXPR Question

88 views
Skip to first unread message

Kyle Murph

unread,
Dec 26, 2009, 12:55:23 PM12/26/09
to Thinking Sphinx
Sorry for the somewhat OT thread here, but I'm using Riddle with
Sinatra, trying to get GeoDist working, and I'm thoroughly confused.

I can get Riddle up and running, and do basic :extended match_mode
searches. It seems I need to use PH_SORT_EXPR for GeoDist, but I
can't seem to get it working.

Here's my terminal session:

> client.sort_mode = :expr
> client.query "hey"
=> {:status=>1, :attributes=>{}, :matches=>[], :fields=>
[], :error=>"index test2: syntax error, unexpected $end near
''", :words=>{}, :attribute_names=>[]}

Am I doing something wrong? Any kind of query causes the same error
after setting sort_mode to :expr.

Any help is greatly appreciated.

Pat Allan

unread,
Dec 26, 2009, 7:57:34 PM12/26/09
to thinkin...@googlegroups.com
Hi Kyle

You'll need to set a value for :sort_by as well - for example:

client.sort_by = '@geodist ASC, @weight DESC'

I'm pretty sure this is what's causing the error. That said, you shouldn't need to use the expression sorting mode - but you do need a reference to @geodist in your sorting or filters for geo searching to come into play. So alternatively, you can use the :extended sort mode (not sure if there's going to be any noticeable speed difference between that and :expr though).

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

Kyle Murph

unread,
Dec 30, 2009, 5:57:40 PM12/30/09
to Thinking Sphinx
Thank you, that fixed the error. I still can't seem to get it working
though -- can you tell me what I'm doing wrong?

i have an entry in my db; lng and lat are set to 1 and 2

in sphinx.conf i have:
sql_attr_float = lat
sql_attr_float = lng

here's my attempt to get it working

client.sort_by = '@geodist ASC, @weight DESC'

client.sort_mode = :extended
client.set_anchor('lat', -0.6591741, 'lng', 2.530770)
client.filters << Riddle::Client::Filter.new("@geodist",
-200.0..200.0, false) # wide range for testing, passing 'geodist'
without '@' in front of it returns an error when i query

> client.query "hey"
=> {:status=>0, :total=>0, :attributes=>{"lng"=>5, "@geodist"=>5,
"lat"=>5}, :matches=>[], :total_found=>0, :fields=>["id", "fullname",
"profile", "birthdate", "gender", "zip", "user_email", "id", "city",
"country_code", "state", "zip", "user_email"], :words=>{"hey"=>
{:docs=>1, :hits=>1}}, :time=>0.001, :attribute_names=>["lng", "lat",
"@geodist"]}

Any idea why all of the attributes have values of 5? What am I doing
wrong?

Thanks again.

Pat Allan

unread,
Jan 2, 2010, 12:51:27 AM1/2/10
to thinkin...@googlegroups.com
Hi Kyle

It's not that the attributes have values of 5, that's just the indication of the data type. Attribute values will be returned for each hash/result in :matches - but you're getting nothing.

Firstly, I'd recommend trying with a range from 0.0 to 200.0 - there's no need to use negative values, it's all just distance from the specified point. If that doesn't help, let us know.

--
Pat

Kyle Murph

unread,
Jan 3, 2010, 6:24:10 PM1/3/10
to Thinking Sphinx
Turns out my range wasn't very big after all, as it returns meters. I
simply needed a much bigger range. All working.

tyvm

Reply all
Reply to author
Forward
0 new messages