Boosting is limited to one boost per field

Created on 10 December 2024, 10 months ago

Respect the submission guidelines above! Drupal.org issue forks cause additional work for the project maintainer!

Setup

  • Solr version:
  • Drupal Core version:
  • Search API version:
  • Search API Solr version:
  • Configured Solr Connector:

Issue

Issue created for the module, it should be for this module
https://www.drupal.org/project/search_api/issues/3351421 πŸ’¬ Boosting is limited to one boost per field Active

✨ Feature request
Status

Active

Version

4.3

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom farse

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @farse
  • πŸ‡¬πŸ‡§United Kingdom farse
  • πŸ‡¬πŸ‡§United Kingdom farse

    I have created a patch for this issue.
    I was then able to make a custom processor to use preprocessSearchQuery to add in the multiple boosts. My example:

      public function preprocessSearchQuery(QueryInterface $query) {
        parent::preprocessSearchQuery($query);
    
        // Get the current user's current language.
        $current_language = $this->languageManager->getCurrentLanguage()->getId();
    
        // Define the language priority order.
        $language_priority = [
          'en' => 6,
          'fr' => 5,
          'es' => 4,
          'ar' => 3,
          'zh-hans' => 2,
          'ru' => 1,
        ];
    
        $language_priority[$current_language] = 8;
    
        // Add a boost based on the langcode field.
        foreach ($language_priority as $langcode => $boost) {
          $query_boost[$langcode] = sprintf('if(eq(%s,"%s"),%2F,0.0)', SolrBackendInterface::FIELD_PLACEHOLDER, $langcode, $boost);
        }
    
        // Works now with search_api_solr_multiple_boost_per_field_3492868_3.patch.
        $boosts['search_api_language'] = $query_boost;
        $query->setOption('solr_document_boost_factors', $boosts);
      }
  • πŸ‡©πŸ‡ͺGermany mkalkbrenner πŸ‡©πŸ‡ͺ

    I don't think that we should add that workaround to search_api_solr.
    The feature request should target search_api first to allow multiple boosts.
    Then the backends should be adjusted accordingly.

  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    Is this a duplicate of πŸ’¬ Boosting is limited to one boost per field Active ?

Production build 0.71.5 2024