Search code examples
solrlucenesunspot

Solr does not find substring


I have a rails 4 application running sunspot solr with the following filters in the schema.xml

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

I have a city named "Alpe d'Huez" which I wan't to be found by solr. Solr only finds this record as long as you start typing Alpe, but I want it to be found by just typing in "huez" How can this be achieved? Thanks for help


Solution

  • Try below configuration and if search term contains special characters then enter search term within double quotes.

    <fieldType name="search" class="solr.TextField" positionIncrementGap="150">
        <analyzer type="index">
            <tokenizer class="solr.KeywordTokenizerFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="50"/>
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.KeywordTokenizerFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
    </fieldType>