Thinking Sphinx? Watch your scopes!

20/08/2010

I ran into this little GOTCHA, and thought it could use some more Google love, so here goes:

If you try to use named scopes with your Sphinx search, they will just be ignored. For example, I had a model JobOffer with this scope:

scope :open, { :conditions => 'job_offers.status = "open" OR job_offers.status = ""' }

And then did a search like this:

@job_offers = JobOffer.open.search query

Which, to my surprise was also showing "closed" job offers.

I found the solution over here; Sphinx has (since version 1.2) it's own form of scopes.

sphinx_scope(:open){ 
  { :conditions => {:status => ['open', '']}}
}

With that sphinx_scope in place, the above search call w├Čll work as expected. (well, obviously I've had to rename it to not clash with the existing Rails scope.)

ArrrrCamp presentation online

21/05/2010

Better late than never right..; I've just uploaded my presentation on Radiant for the third edition of ArrrrCamp:

What the fuzz is all about

  1. 2 pages are tagged with WYM
  2. 1 page is tagged with absolute-urls
  3. 1 page is tagged with arrrrcamp
  4. 2 pages are tagged with documentation
  5. 2 pages are tagged with editor
  6. 2 pages are tagged with extension
  7. 2 pages are tagged with extensions
  8. 1 page is tagged with minitorial
  9. 1 page is tagged with navigation
  10. 10 pages are tagged with radiant
  11. 4 pages are tagged with rails
  12. 2 pages are tagged with ruby
  13. 2 pages are tagged with shell
  14. 1 page is tagged with sifr
  15. 2 pages are tagged with troubleshooting

Github activity

More places where you can find me

Back to top