Solr search not giving exact result for single word term

Viewed 307

I am a very beginner in solr search queries where I am trying to get exact results for my given term. I am getting exact result for terms which have more than one word. But for terms which have only one word I am not getting exact search result. Before down voting or closing this question consider the scenario. I am asking exact search for single word.

For ex

  1. If I search "ship to add" I get result ship to address

  2. Plant: I get results like Plant Number, Plant Type, Plant description,and then Plant I want my Exact word Plant to come first then I want other related searches to come

Approaches I have tried

/query?q=(name:"PLant")&stopwords=true           //giving output I mentiond above

/query?q=(name:"^PLant$")&stopwords=true        //not giving any output

/query?q="PLant"&stopwords=true                //giving fuzzy output

Any help will be appreciated.

1 Answers

You need to use the string as fieldtype for your field name.

Apply the String as fieldtype and reindex the data.

<field name="name" type="string" indexed="true" stored="true" required="true" multiValued="false" />

String stores the word/sentence as an exact string without performing any tokenization on it. Its useful in cases for storing exact matches, e.g, for faceting, sorting.

Opposite of string type is text. Text does the tokenization of data, performs processing such as lower-casing etc. It is helpful in case when we want to match part of a sentence.

If you want achieve the lowercase search then use the below fieldtype for you field.

<fieldType name="forExactMatch" class="solr.TextField" sortMissingLast="true" omitNorms="true">
      <analyzer>
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory" />
      </analyzer>
    </fieldType>

Then your field defination will look like below

<field name="name" type="forExactMatch" indexed="true" stored="true"/>
Related