ruby-on-rails – Mapear Substring Solr


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 succeeding in part:

# modelCity.rb
searchable do
  text :name 

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

city ​​database:

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

If I type for example "Cascavel" it brings up the right search, but if I type "Casca" I want it to bring up all the cities that have those words related to the name. Does anyone know how I do this?


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

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

* In this way, the framework already handles problems like SQL Injection

Scroll to Top