Question

I am new to solr, please help me in boosting fields.

I have a query like this,

q=name:test* OR description:test*

i want to apply boosting/weight age for name its 500 and for description its 50.

for example: lets consider "test" term is appearing for 1 time in name field in one record and 20 times in description field its from another record, then boosting calculation should happen like below.

for name: 1 X 500 = 500

for Description: 20 X 50 = 1000.

as result the records with high boosting value should come at top. so based on above calculation the record which having description field with 20 matches should come on top after that record with 1 match in name field.

If any one have solution for this, please provide

Thanks in advance.

Was it helpful?

Solution

You can boost a field at index time with the boost attribute, or you can apply a boost in the query, such as q=name:test*^50 OR description:test* (and there are some more advanced features here as well).

I bears noting though, Lucene, by default, applies a length normalization that effectively weighs matches on shorter fields more heavily than longer fields. It sounds a bit like that is what you are trying to recreate.

If you need the scoring calculation to be as simple as what you have provided, you would need to write your own Similarity class, I believe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top