Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr normalization score

Tags:

solr

I wanted to know if there is a way to know if the first result in the solr response is an exact match of my query? for example i'm searching for documents with the words: "iphone 6s 64GB gold"

I got 3 results:

1) The first result with the words "iphone 6s 64GB" with score: 187.86491

2) The second result with the words "iphone 6s" with score: 170.36568

3) The third result with the word "iphone" with score: 136.68152

When i normalize the scores i got these new scores:

1) score 1.0
2) score 0.92
3) score 0.66

the problem here is that the first result got score 1.0 (only because it the first result with the higher solr score , but it can't testify that it's an exact match ) while ,in my opinion ,it's should be ~0.5 because it's not an exact match. I want to know if the results that i got are really relevant or not and to take only the "most relevant" results - for example: only the results with score > 0.6. But i can't do it now because 0.6 doesn't testify the real relevancy.

like image 895
Zdev Avatar asked Jul 03 '26 03:07

Zdev


2 Answers

There is no such thing as a "real relevancy", which is why the top score isn't normalized for 1.0. Things can be considered more or less relevant based on the parameters you give Solr (such as how to score individual fields against each other). What would "60% relevancy" really mean in this context? Scores between queries are (usually) not comparable, and will change depending on the contents of the index (if a new document with the same terms are indexed, the scores for the previous query might be reduced if run again).

If you want to prioritize exact matches, add a field with a KeywordTokenizer and a LowercaseField, and score that field higher (through qf=). If case matters, use a StrField instead (which will give you only perfectly exact matches) and score that field higher.

If you want to require all terms to be present, use q.op=AND, which won't give any hits if all fields aren't present. If you want to do more advanced matching, use the mm parameter to say exactly how many terms need to match (which you can do as a percentage, within an interval, etc.).

These settings are relevant when you're using the dismax or edismax query handler, which it sounds like you're doing from your question.

like image 151
MatsLindh Avatar answered Jul 06 '26 00:07

MatsLindh


in order to do what you ask (not considering why you want to do that), you could:

  1. use highlighting to return what is matched in the docs
  2. compare the query string to the highlighted fragments and verify whether it is a perfect match

Caveats:

  1. if you are using stemmers etc, an exact match could mean just matching part of a term. So you cannot just use a string comparison, you need to run both the query string and the fragment through each analysis chain first (query string through query analysis, fragments through index analysis)
  2. depending on the highlighting type, you might need certain features on your fields.
like image 24
Persimmonium Avatar answered Jul 06 '26 00:07

Persimmonium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!