Niranjan Kumar
Niranjan Kumar

Reputation: 1518

Purpose of solr boost function

I came across a set of legacy code in which some dynamic variables are set to solr boost function.

String query = "{!boost b=sum(" + searchQuery.getFieldsToBoost() + ")}";

This breaks in case searchQuery.getFieldsToBoost() contains any of these punctuations + - && || ! ( ) { } [ ] ^ " ~ * ? : \

So I tried to escape these special chars in boost sum() function , using the approach given in https://lucene.apache.org/core/2_9_4/queryparsersyntax.html

But the above approach didn't work.

Following is the error:

Caused by: org.apache.lucene.queryParser.ParseException: Expected ',' at position 631 in 'sum(itemAttributes_A3,itemAttributes_ASD,itemAttributes_ASD1,itemAttributes_Bang,itemAttributes_Color,itemAttributes_ES,itemAttributes_El_Segundo_only,itemAttributes_Environment_Friendly,itemAttributes_MossPoint_only,itemAttributes_NAUFIL,itemAttributes_NorthDakota_only,itemAttributes_Off_Contract,itemAttributes_On_Contract,itemAttributes_PBINFO,itemAttributes_PPD,itemAttributes_Palmdale_only,itemAttributes_Preferred,itemAttributes_Punchout,itemAttributes_RanchoBernardo_only,itemAttributes_SEARCHABLE,itemAttributes_Services,itemAttributes_SpacePark_only,itemAttributes_custom_flag12,itemAttributes_FL_01,itemAttributes_hyphen\-field,itemAttributes_icon,itemAttributes_required_PPD,itemAttributes_semicolon;field,itemAttributes_space_field,attributes_Green_certified,attributes_Preferred_contract,attributes_Service_Disabled_Veteran,attributes_Veteran_Owned,attributes_Minority_Owned,attributes_Woman_Owned,attributes_Hubzone,attributes_Tier_II_Contract,attributes_Red_Attribute)'

So I thought of replacing all special chars in searchQuery.getFieldsToBoost() to underscore.

But I don't know how it will effect the search results / boost results.

Basically it would be very nice if someone can help me with escaping the special chars or can give me an overview of repercussions after replacing special characters to underscore.

I am failing to understand what is the purpose of boost in solr.

Upvotes: 0

Views: 470

Answers (1)

Mysterion
Mysterion

Reputation: 9320

The purpose of the boosting function is to boost specific terms or documents or fields, when returning results. It will not add or change result set, e.g. it could only change the order.

So, for example if you decided that field title, is more important than description, you could set it with boosting. Same could be done, if you decided, that term Nike is more important than term Adidas.

Some additional information here

Upvotes: 1

Related Questions