Search code examples
solr

Solr single word search not giving exact result


Using Solr 8.11.1. Added title, description, and company name as a String type in Jobs core. Made 'tdc' copyField in 'text_en' type. Using AND condition in q.op param. if I search 'PHP developer' means it gives the exact result, but if I search 'developer' alone it fetches a lot of results that contain 'develop'. I need the exact result of 'developer'.

This is my query

cat:JOB AND tdc:("developer")

Solution

  • The text_en field type uses the solr.PorterStemFilterFactory in it.

    solr.PorterStemFilterFactory : This filter applies the Porter Stemming Algorithm for English.

    For eaxmple if your field type is like below with PorterStemFilterFactory.

    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory "/>
      <filter class="solr.PorterStemFilterFactory"/>
    </analyzer>
    

    your input for indexing is : "jump jumping jumped"

    Tokenizer passed to Filter is : "jump", "jumping", "jumped"

    the end Output is : "jump", "jump", "jump"

    If you don't want stemming then you may need to remove this PorterStemFilterFactory from you field type definition and re-index the data.

    Same is happening in your case for the word developer.

    And if you are looking for exact match you can use the having a KeywordTokenizer with a LowercaseFilter as field type for your field.

    <analyzer>
      <tokenizer class="solr.KeywordTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>