Question

In my rails application, i'm using solr search. Substring matching working fine on local server but it is matching full words on my deployment server.

searchable block

searchable do
  text :firstname, :lastname, :login, :mail
  boolean :member
  integer :status
end

schema.xml is.

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StandardFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.PorterStemFilterFactory"/>
    <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="10" side="front" />
  </analyzer>
</fieldType>

What am i doing wrong?

Was it helpful?

Solution

(Adding an answer here to inform you of possible undesired behavior)

FYI, When you make changes to the "text" fieldType in the schema.xml you are changing the configuration for every indexed text field in your application. Sometimes this is not desired as some fields will need a custom configuration.

For example, let's say (for whatever reason) that you wanted to treat first names differently than other text fields. Let's say you wanted to add synonyms of first names. You would first create a new fieldType in your schema.xml called first_name

<fieldtype name="first_name" class="solr.TextField" positionIncrementGap="100">
  <analyzer>
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
  </analyzer>
</fieldtype>

Then in the fields section of the schema.xml file, you would add two new dynamic fields

<dynamicField name="*_first_name"  stored="false" type="first_name" multiValued="false" indexed="true"/>
<dynamicField name="*_first_names" stored="true"  type="first_name" multiValued="false" indexed="true"/>

NOTE: The 's' on the dynamicField name is to denote that it's a stored type, providing the * for the dynamic field helps with the sunspot configuration

So in your searchable block, you can now do:

searchable do
  text :firstname, :as => :user_first_name
  text :lastname, :login, :mail
  boolean :member
  integer :status
end

This will now use your custom-configured "first_name" field.

If you wanted first_name to be a stored value (and you still wanted to use your custom configuration) you would implement your searchable block like:

searchable do
  text :firstname, :stored => true, :as => :user_first_names
  text :lastname, :login, :mail
  boolean :member
  integer :status
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top