Search using Solr in rails

1

If I search for a piece of a word other than the first few characters of the word it does not find. Type if I search for "Car" it searches correctly, but now if I search for "los" or "arlos" it returns empty.

I have in the Client table:

id  name
 1  Carlos da Silva
 2  Tiago Casanova
 3  Pedro Gomes

In my model:

searchable  do
    text :name
end

No controller:

@clients = Client.search do
 fulltext params[:search]
 paginate :page => params[:page] || 1
end

In my schema.xml

 <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" />
        <filter class="solr.PorterStemFilterFactory" />   
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.ASCIIFoldingFilterFactory" />
      </analyzer>
  </fieldType>
    
asked by anonymous 05.01.2015 / 13:21

1 answer

0

For the type of search you want I see two alternatives

1) Make in query time a complement in your search with the * of the two sides so the SOLR should search using the string:

@clients = Client.search do
 fulltext "*#{params[:search]}*"
 paginate :page => params[:page] || 1
end

2) The tokenizer you are using is the solr.StandardTokenizerFactory , in case you wanted to reindex using another tokenizer you can use solr.NGramTokenizerFactory with min and max from jail. So it will index the words by chains, you can specify the maximum and minimum size of the chain, just be careful not to put a very small maximum.

For more examples follow the Solar documentation, for the tokenizer topic

link

    
07.01.2015 / 04:44