Exact word match Solr

2019-09-01 09:15发布

问题:

I want to the exact results for my query.

For e.g. when I search "New york" , then it doesn't give me exact results about New York But it also gives me results like:

"New York"

"New Delhi"

And other cities starting from "New"

So how can I get only results for "New York"?

回答1:

Phrase query should do the job. Just put quotes around your query terms.



回答2:

From your question What i Understand is you want "New York" to be consider as single token ,you can do that by modifying tokenizer for field Change Tokenizer from StandardTokenizerFactory to KeywordTokenizerFactory reindex data and query again



回答3:

Depending on exactly what you expect to get as search results, Stupid Lucene Tricks: Exact Match, Starts With, Ends With might also be worth a look.