Turning on/off stemming

Go To StackoverFlow.com

0

I've modified schema.xml to have two fields, one for stemming, and one for no stemming. I also used copy Field to copy one to the other. Finally in solrconfig.xml I added the appropriate dismax. Is this everything that needs done? I have a feeling I'm missing something. What is the best way to test of it works, through SOLR admin panel? Is there another way to test it?

In solrconfig.xml:

<requestHandler name="dismax" class="solr.SearchHandler" >
  <lst name="defaults">
  <str name="defType">dismax</str>
  <str name="echoParams">explicit</str>
  </lst>
</requestHandler>

In schema.xml:

  <field name="contents" type="text_general" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true"/>
 <field name="contents_a" type="text_en_splitting" indexed="true" stored="true" termVectors="true" termPositions="true" termOffsets="true"/>

  <!-- A general text field that has reasonable, generic
     cross-language defaults: it tokenizes with StandardTokenizer,
 removes stop words from case-insensitive "stopwords.txt"
 (empty by default), and down cases.  At query time only, it
 also applies synonyms. -->
  <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <charFilter class="solr.HTMLStripCharFilterFactory"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <charFilter class="solr.HTMLStripCharFilterFactory"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>


 <fieldType name="text_en_splitting" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
  <analyzer type="index">
    <charFilter class="solr.HTMLStripCharFilterFactory"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <!-- Case insensitive stop word removal.
      add enablePositionIncrements=true in both the index and query
      analyzers to leave a 'gap' for more accurate phrase queries.
    -->
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords_en.txt"
            enablePositionIncrements="true"
            />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
    <filter class="solr.EnglishMinimalStemFilterFactory"/>
  </analyzer>
  <analyzer type="query">
  <charFilter class="solr.HTMLStripCharFilterFactory"/>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords_en.txt"
            enablePositionIncrements="true"
            />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
    <filter class="solr.EnglishMinimalStemFilterFactory"/>
  </analyzer>
</fieldType>

  <copyField source="contents" dest="contents_a"/>
2012-04-04 20:57
by solr_user


2

To test the stemming of your fields, yes, you should be able to do everything you need with the "Field Analysis" tool on the admin panel. (Click "Analysis").

At the top, put in your field name. (contents_a)

Put in a test value that stems, and you should see the results pretty clearly.

You can check the "verbose" checkbox on the top half to get an ultra-detailed view of what filters are running on the field, in order.

2012-04-04 21:09
by Dan Fitch
Is this the same as FuzzyQuery in SOLR 4.0 or is that a different methodology - solr_user 2012-04-04 21:32
How do I control stemming with the number of wildcard characters - solr_user 2012-04-04 21:41
Fuzzy is in 1.3, but you can't use it with the dismax handler. ... I'm not sure what you mean about stemming and wildcards. Check the docs for the EnglishMinimalStemFilterFactory, you may want to switch to the SnowballPorterFilterFactory with language="English"Dan Fitch 2012-04-04 22:06
Ads