views:

355

answers:

1

I am using Sphinx with the Thinking Sphinx plugin. I have indexed a model called Venue with the following code (and the rake thinking_sphinx:index command)

define_index do
    indexes :name
    indexes city
    indexes zip
end

I obtain the results in my controller with this code:

@venues = Venue.search params[:search]

and I render them as json. The problem I have is that when I hit this URL:

http://localhost:3000/venue/list?search=Baltimo

I get nothing. But when I hit this URL:

http://localhost:3000/venue/list?search=Baltimor

I get all Venues located in the city of Baltimore. For some reason that one character makes a difference. Theoretically, I should be getting all Venues in Baltimore if I just search with one character - 'b'

Does anyone know what is going on here?

Thank you

+4  A: 

Hi Tony

Unless you have enable_star set to 1 and min_prefix_len or min_infix_len set to 1 or more, you won't get B to match Baltimore (and even then, I think you need to search for B* to get the match).

What's happening here is that by default, Thinking Sphinx tells Sphinx to use an English stemmer, which allows for similar words (by characters, not by meaning) to be considered matches, so it puts Baltimor and Baltimore in the same basket.

If you want to get any part of any word matched, then you need to put something like the following in config/sphinx.yml:

development:
  enable_star: 1
  min_infix_len: 1
test:
  enable_star: 1
  min_infix_len: 1
production
  enable_star: 1
  min_infix_len: 1

Then stop Sphinx, re-index, and restart Sphinx. Once you've done that, then searches for B* should return Baltimore.

Hope this helps.

pat
sweet, just found that on the sphinx documentation...but couldn't find where it said to put that in the yml. thank you!
Tony
Is there a way where they don't have to type an * at the end? Like search wood would pull up wooden and woodworking without having to type wood*
Mike