I'm trying to add a boost to a search api Solr query when a field has a particular value, e.g. when its nid = 123. Looking at Solr version 8.7 docs for boosting (my solr server version), this looks pretty straightforward. I just need to add a bq parameter like:
bq=nid:123^10
When I go to my Solr server's admin UI and add a query there - first checking the edismax parser checkbox, and then adding nid:123^10
into the bq field - I see results where my node with nid is at the top of the list (as I'd expect) with all other results after it. If I remove the option, my node with nid 123 is no longer at the top (also as I'd expect).
The search_api_solr module provides a hook to alter queries, hook_search_api_solr_query_alter(), where I can add my boost. (Side note, I've used this hook in the past to boost results based on a date basically as documented in this bkosborne comment.)
My understanding is that I should be able to implement something like:
function MY_MODULE_search_api_solr_query_alter(\Solarium\Core\Query\QueryInterface $solarium_query, \Drupal\search_api\Query\QueryInterface $query) {
$solarium_query->addParam('bq', 'nid:123^10');
}
However, this has no impact on the relevancy scores of my results (I'm printing the relevancy score in my view and my node with nid 123 has the same score whether I add this parameter or not), nor, predictably, the order of the results.
What am I missing here?
Version Information:
- Drupal core: 9.1.10
- Search API: 8.x-1.19
- Search API Solr: 4.1.12
- Solr Server: 8.7.0
p.s. my nid field key is actually its_nid
in the index, but I just used nid
in this question for readability.