This is a big question and feature discussed for inclusion in Sunspot.
Sunspot uses dynamic field naming conventions to customize its schema. For example, here are two existing definitions for text fields:
<dynamicField name="*_text" stored="false" type="text" multiValued="true" indexed="true"/> <dynamicField name="*_texts" stored="true" type="text" multiValued="true" indexed="true"/>
They correspond to fieldType name="text" defined earlier in the schema.
<fieldType name="text" class="solr.TextField" omitNorms="false"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.StandardFilterFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType>
You can add a similar definition for the different languages ββyou want to index (as Mauricio mentions), and then set up some new dynamicField definitions to use them.
1. A fieldType for a French text field
<fieldType name="text_fr" class="solr.TextField" omitNorms="false"> <analyzer> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.SnowballPorterFilterFactory" language="French"/> <filter class="solr.StandardFilterFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType>
2. A dynamicField for a French text field
<dynamicField name="*_text_fr" stored="false" type="text" multiValued="true" indexed="true"/> <dynamicField name="*_texts_fr" stored="true" type="text" multiValued="true" indexed="true"/>
3. Using a French text field in Sunspot
The latest Sunspot 1.2 (not completely released - use 1.2.rc4) supports the :as parameter, which allows you to specify a field name.
searchable do text :description, :as => 'description_text_fr' end
As I said, this is what I am going to add to Sunspot 1.3 or 1.4. Personally, I would like to see something like :lang => :en in the text field definition to select the appropriate field definition. Feel free to call your thoughts on the Sunspot mailing list!
Nick zadrozny
source share