Skip to content

Instantly share code, notes, and snippets.

@nz
Created April 9, 2012 15:25
Show Gist options
  • Select an option

  • Save nz/2344212 to your computer and use it in GitHub Desktop.

Select an option

Save nz/2344212 to your computer and use it in GitHub Desktop.
Add NGram analysis to Sunspot
<?xml version="1.0"?>
<schema>
<types>
<fieldType name="text" class="solr.TextField" omitNorms="false">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_ngram" class="solr.TextField" omitNorms="false">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="6" side="front"/>
</analyzer>
</fieldType>
<!-- ... -->
</types>
<fields>
<!-- ... -->
<dynamicField name="*_text_ngram" type="text_ngram" stored="false" multiValued="true" indexed="true"/>
<!-- ... -->
</fields>
</schema>
class Article < ActiveRecord::Base
searchable do
text :firstname # creates firstname_text field
text :firstname, :as => 'firstname_text_ngram'
end
end
@ikaiser
Copy link
Copy Markdown

ikaiser commented Apr 30, 2015

where put this code??
thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment