Solr Partial And Full String Match

Scripthead picture Scripthead · Jan 28, 2011 · Viewed 34.5k times · Source

I am trying to allow searches on partial strings in Solr so if someone searched for "ppopota" they'd get the same result as if they searched for "hippopotamus." I read the documentation up and down and feel like I have exhausted my options. So far I have the following:

Defining a new field type:

<fieldtype name="testedgengrams" class="solr.TextField">
   <analyzer>
     <tokenizer class="solr.LowerCaseTokenizerFactory"/>
     <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front"/>
  </analyzer>
</fieldtype>

Defining a field of type "testedgengrams":

<field name="text_ngrams" type="testedgengrams" indexed="true" stored="false"/>

Copying contents of text_ngrams into text:

<copyField source="text_ngrams" dest="text"/>

Alas, that doesn't work. What am I missing?

Answer

Mauricio Scheffer picture Mauricio Scheffer · Jan 28, 2011

You're using EdgeNGramFilterFactory which generates tokens 'hi', 'hip', 'hipp', etc, so it won't match 'ppopota'. Use NGramFilterFactory instead.