James Tang
James Tang

Reputation: 611

Can Solr search key words precisely?

For example: I want to search "support", I hope it will only return the results containing "support", and do NOT return the result containing "supports" or any other relevant matches.

Is it possible to implement like this?

Thanks.

Upvotes: 1

Views: 1821

Answers (2)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99720

Yes, if you search against an unanalyzed field type, matches are exact. In the default Solr schema the unanalyzed field type is named "string" (of class "solr.StrField")

EDIT: it depends on what you mean by "precisely". If your field value is "support desk" and your query is "support", should it match?

  • If your answer is yes, then you should look into configuring stemming.
  • If your answer is no, i.e. the query must match the field value and nothing else, then you should use a string (i.e. unanalyzed) field type.

Furthermore, if your query is "supports" and the field value is "Supports", should it match?

  • If you answer yes, then you should use a LowerCaseFilterFactory (you can't do this on a string field type, you'll have to switch to a text field type).
  • If you answer no, then it's ok to use a string field type.

In summary, the Lucene/Solr text analysis pipeline is very configurable, take a look at the analyzer docs for a reference of all available options.

Upvotes: 7

Edouard Tabet
Edouard Tabet

Reputation: 158

What you are describing is called stemming. There is another almost identical question on stack overflow, check it out : Solr exact word search You will need to re-index and disable stemming in your configuration. I don't believe it's possible to do that at query time since what is stored in your index is the stemmed version of the word. In your case "support" is stored in the index even is "supports" is displayed. This should get you started How to configure stemming in Solr?

Upvotes: 3

Related Questions