Freelancing Gods 2015

14 Nov 2007

Sphinx's Riddle

Edit: I’ve changed the Subversion reference to Github, and it’s worth noting that Riddle works with Sphinx 0.9.8, 0.9.9 and 1.10-beta at the time of writing (January 2011). Original post continues below:

Built out of the work I’ve done for Thinking Sphinx (which has just got basic support for delta indexes, attributes and sorting – although the documentation doesn’t reflect that), I’ve extracted a new Ruby client that communicates with Sphinx, which I’ve named Riddle.

I’m not going to delve into the code here – because I’m not expecting it to be that useful to many people (and I just wrote examples in the documentation – go read that instead!) – but I’m very happy with how it’s ended up, and it’s got some level of specs to give it a thorough test. It’s also compatible with the most recent release of Sphinx (0.9.8 r871). Should you wish to poke around with it, just clone it from Github:

git clone \

It’s also being used in Evan Weaver’s UltraSphinx plugin, which I’m pretty pleased about.


8 responses to this article

14 Nov 2007
Bork said:

Bork Bork Bork.

23 Nov 2007
Joost said:

Works excellent this one! Thanks!

23 Apr 2008
golak said:

Thanks for the wonderful ruby wrapper for sphinx api. I am using it on a project of mine. I won’t be using thinking sphinx because of the architecture that i have adopted. could you please clarify one simple doubt which i am somehow getting wrong. how do i use the sorting mode SPH_SORT_EXPR
i tried the following syntax but its generating error
riddle.sort_mode = :expr
riddle.sort_by = ‘@weight * page_rank DESC

thanks for your help in advance

23 Apr 2008
pat said:

Hi golak

I’ve not had the opportunity to use the expression sorting mode – but your syntax looks right to me. Perhaps remove the DESC? None of the examples in the documentation have that. If that doesn’t help, shoot me an email with the error stack trace, I’m happy to look into it.

01 Apr 2009
Rodrigo Aronas said:

I’m newby in ultrasphinx, and i’m egtting a headache trying to use the mode :expr with RoR.
Here’s what I’m using:
#search = => @types, :query => "*#{query}*", :per_page => per_page, :page => @page, :weights => @weights, :filters => @query_filters, :sort_mode => 'expression', :sort_by=>['weight +trust*100 – deprecated * 10000 + rating_count * 1000 -percent_variation*100 -monetary_price’])

And i’m getting an error of SortMode invalid.

does anybody knows the way to do this?
Thanks in advance!

01 Apr 2009
pat said:

Hi Rodrigo

I’m not entirely sure how UltraSphinx works, but if it is just passing through the sort_mode argument to Riddle, then you want to use :expr instead of 'expression'.

15 Apr 2009
Rodrigo said:

Hello again, I went back on this sphinx stuff that didn’t work for me, and i’m still having this problem, it continues giving me the "Sortmode “expr” / “expression” or whatever i put INVALID.
I’m stucked with this, any comments would be appreciated.

16 Apr 2009
pat said:

Hi Rodrigo

Are you setting sort_mode as a symbol or a String? Because it needs to be a symbol. If you want to continue this discussion on the Thinking Sphinx google group, then we can discuss this further, and with code examples.

Leave a Comment

Comments are formatted using Textile. Please be respectful of others when posting comments. Be nice.

RssSubscribe to the RSS feed

Related Links

Related Posts

About Freelancing Gods

Freelancing Gods is written by , who works on the web as a web developer in Melbourne, Australia, specialising in Ruby on Rails.

In case you're wondering what the likely content here will be about (besides code), keep in mind that Pat is passionate about the internet, music, politics, comedy, bringing people together, and making a difference. And pancakes.

His ego isn't as bad as you may think. Honest.

Here's more than you ever wanted to know.

Open Source Projects

Other Sites

Creative Commons Logo All original content on this site is available through a Creative Commons by-nc-sa licence.