1
votes

I have the following questions, I have the model city (name, uf, province)'m trying to implement the method of sunspot research, 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 data base:

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

If I type for example "Cascavel" he brings a certain quest, but if I type in "Casca" I want him to bring all the cities that have those words related to the name. Anyone know how to do it?

OBS: Using rails 4, followed the tutorial: git sunspot

1

1 Answers

1
votes

You will need to configure this in the Solr schema.xmlto compute N-grams for your text fields. Here's one possible example:

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="15"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

The Solr Wiki has lots of detail on this; I generally end up Googling "do x in Solr" or "why is solr doing y". Lucky for us there are a lot of smart people out there using Solr.