Map Substring Solr

Asked

Viewed 69 times

3

I have the following question, I have the model city(name, uf, province) I’m trying to implement the Sunspot search method, but I’m getting it on my own:

# modelCity.rb
searchable do
  text :name 
end 

# controller City
unless params[:search] 
  @cities = City.paginate(:page => params[:page], :order => "name ASC")
else
  @search = City.search do
    fulltext params[:search]
  end
  @cities = @search.results
end

City database:

1 Medianeira PR 3
2 Cascavel   PR 4
3 Cascavemat PR 3

If I type for example "Rattlesnake" it brings the right search, but if I type "Bark" I want it to bring all the cities that have those words related to the name. Someone knows how I do it?

1 answer

1

If you are using an SQL Database, you can use wildcards:

query = "CASCA"
City.where("name like ?", "%#{query}%")

*This way, the framework already treats problems like SQL Injection

  • Although it works I think OP wants a solution to use with Solr and not in sql.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.