Map Substring Solr

3

I have the following question, I have the city(name, uf, province) model I'm trying to implement the sunspot search method, but I'm getting by:

# 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 cities that have these words related to the name. Does anyone know how I do this?

    
asked by anonymous 25.02.2014 / 14:06

1 answer

1

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

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

* In this way, the framework already addresses issues such as SQL Injection     

27.02.2014 / 16:49