Partial Word Searching with Apache Solr/Drupal 7

Public

adding this line (#22) to schema.xml will return partial word searches in Solr

</> CopyGet raw version
php
  1. <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
  2. <analyzer type="index">
  3. <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
  4. <tokenizer class="solr.WhitespaceTokenizerFactory"/>
  5. <!--
  6. in this example, we will only use synonyms at query time
  7. <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
  8.  
  9. -->
  10. <!--
  11. Case insensitive stop word removal.
  12. add enablePositionIncrements=true in both the index and query
  13. analyzers to leave a 'gap' for more accurate phrase queries.
  14.  
  15. -->
  16. <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true"/>
  17. <filter class="solr.WordDelimiterFilterFactory" protected="protwords.txt" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1" preserveOriginal="1"/>
  18. <filter class="solr.LengthFilterFactory" min="2" max="100"/>
  19. <filter class="solr.LowerCaseFilterFactory"/>
  20. <filter class="solr.SnowballPorterFilterFactory" language="English" protected="protwords.txt"/>
  21. <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  22. <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="30"/>
  23. </analyzer>

Comments

MS's picture

Dear,

Thank you for this.
I use the the apachesolr module from drupal.org and edited the schema file.

But this did not have any success.

I use a search field in my view to access search.
Full word search works perfectly.

Thanks in advance

cdmo's picture

remove `Edge` to make this work from the middle of words and the end. For example:

search: "beth"
returns "beth, elizabeth, bethany"

otherwise, using edge:

search: "beth"
returns "beth, bethany"