0

How do I search for an exact phrase in solr. Suppose, when I search for "How_to_Search_this" then it should give me the results of
1. "how_to_search_this" (case insensitive)
2. "How_to_search_this"

but not the results like
1. "How_to_search_this_thing"
2. "How_to_search_that_thing"

Please help.Thanks!

sanjeeda
  • 131
  • 1
  • 10

1 Answers1

0

Do only get exact, lowercase hits, use a KeywordTokenizer. KeywordTokenizer keeps the input string as a single token, but while string does the same, KeywordTokenizer allows you to attach filters as well.

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

This will only give you hits when the query value is identical to the indexed value, except for case.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Actually, I already am using the solr.NGramTokenizerFactory tokenizer. I need it for other requirements. Can we not implement the **Exact phrase search** using this tokenizer? – sanjeeda Jul 11 '18 at 07:21
  • Use different fields for different needs and use cases. An NgramTokenizer will not be suitable for exact phrase search, since it'll generate _many_ tokens for each term. Use `copyField` to index the same content into multiple fields. – MatsLindh Jul 11 '18 at 08:02