How to enable a partial match with the sunspot for rails?

I just made a setting for sunspot_rails and it seems to work fine except for one. After I made 3 entries as below

  • name = John
  • name = John2
  • name = John3

when I search for the keyword "John", only the first entry appears. it seems like a complete coincidence. I would like all of them to appear as a search result.

Is this supposed to happen by default? or did I install something incorrectly ??

+4
source share
2 answers

If you want to return substrings in full-text search, you can look

https://github.com/sunspot/sunspot/wiki/Matching-substrings-in-fulltext-search

You can also add the sunspot_solr.rb file to paginate the results in myapp / config / initializers / with:

 Sunspot.config.pagination.default_per_page = 100 

returns 100 results for this case.

Added:

Your schema.xml file is based on yourappfolder/solr/conf

You can also add <filter class="solr.NGramFilterFactory"/> to match arbitrary substrings.

This is my specific configuration for schema.xml:

 <fieldType name="text" class="solr.TextField" omitNorms="false"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.StandardFilterFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> <fieldtype class="solr.TextField" name="text_pre" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.NGramFilterFactory" minGramSize="2" maxGramSize="10"/> <filter class="solr.ISOLatin1AccentFilterFactory"/> <filter class="solr.TrimFilterFactory" /> <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="10"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> <filter class="solr.ISOLatin1AccentFilterFactory"/> <filter class="solr.TrimFilterFactory" /> </analyzer> </fieldtype> 

For me, this works great with full lines and substrings for all keywords. Please remember to restart the server and re-index your models for the changes to take effect.

Hello!

+8
source

Thanks!!!

block from the girl’s controller (girls_controller.rb)

 def index @search = Girl.search do fulltext params[:search] end @girls = @search.results # @girls = Girl.all # # respond_to do |format| # format.html # index.html.erb # format.json { render json: @girls } # end end 

block from the model Girl (girl.rb)

 searchable do text :name_en, :name_es, name_ja end 
0
source

All Articles