8

I am using the solr backend for search_api on a drupal 8 site.

I have added the value of a taxonomy term reference field (field_promoted_search) to the index.

If an item of content has field_promoted_search with value matching the search term, I would like it to get a significant boost (eg ^1000), pushing it to the top of the search results.

Adding a high 'boost' value at admin/config/search/search-api/index/content/fields worked as expected when the server was using solr <6, but since moving to 6.1.0, this does not work as expected. This may be because search_api_solr/solarium is using a multiplicative boost rather than additive. This is not seem as useful to me as this multiplies the relevance achieved by other fields, rather than solely privileging field_promoted_search, though I am uncertain of this aspect.

I have tried adding a boost query for this promoted search field to the solarium query using hook_search_api_solr_query_alter. This requires me to pass each search key as a boosted query, and the effect seem to be affected by the order of the keys (and also my result does not end up top).

$keys = $query->getKeys();
unset($keys['#conjunction']);
// Boost results where search term matches promoted search field.
$boost_keys = [];
$boost_value = 1000;
foreach ($keys as $key) {
  $boost_keys[] = '"' . $key . '"^' . $boost_value;
}
$solarium_query->getEDisMax()->setBoostQuery('ss_promoted_search:' . implode(' OR ', $boost_keys));

When I attempt to use a boost function instead, I get an error from back from Solr and the query does not run (I have tried several functions).

// Format is: "funcA(arg1,arg2)^1.2 funcB(arg3,arg4)^2.2"
$solarium_query->getEDisMax()->setBoostFunctions("ord(ss_promoted_search,1)^1000");

Any advice much appreciated.


My reference for additive vs multiplicative boost methods is this very helpful article.

-2

None of the API function provided by Search API and Search API Solr Drupal work properly. You can either check solarium docs or switch back to Solr 5 or Solr 4. Boosts work properly with Solr 5.x. Data type indexed is also important. Try indexing it as Fulltext field.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.