Search using Solr in Rails

Asked

Viewed 105 times

1

If I search for a piece of a word other than the first characters of the word he doesn’t think. Like if I search for "Car" it searches correctly, but now if I search for "los" or "arlos" returns me empty.

I have in the Client table:

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

On my model:

searchable  do
    text :name
end

On the 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>

1 answer

0

For the type of search you want I see two alternatives

1) Make in query time an add-on in your search with the * on both sides so 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, if you wanted to reindexar using another tokenizer you can use the Solr.Ngramtokenizerfactory with min and max from jail. So it will index the words by strings, you can specify the maximum and minimum size of the string, just be careful not to put a very small maximum.

For more examples follow solar documentation, for tokenizer topic

https://cwiki.apache.org/confluence/display/solr/Tokenizers#Tokenizers-N-GramTokenizer

Browser other questions tagged

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