Boosting boolean fields in Solr

后端 未结 2 1278
小蘑菇
小蘑菇 2021-02-08 21:42

Is it possible to boost boolean fields in Solr so that they receive a higher score?

We\'ve got an index which looks a bit like this:

  • document_id
  • t
2条回答
  •  误落风尘
    2021-02-08 22:05

    Drupal

    Here is the solution for those who're using Drupal CMS.

    First, find your field name in Schema Browser at /solr/admin/schema.jsp

    Then, depending on the module which you use, try the following examples:

    Apachesolr module

    Code example:

    /**
     * Implements hook_apachesolr_query_alter().
     */
    function hook_apachesolr_query_alter(DrupalSolrQueryInterface $query) {
      $query->addParam('bq', array('is_review' =>
        '(is_review:true^100 OR is_review:false^0)'
      ));
    }
    

    Search Solr API module

    Code example:

    /**
     * Implements hook_search_api_solr_query_alter().
     */
    function hook_search_api_solr_query_alter(&$call_args, SearchApiQueryInterface $query) {
      $call_args['params']['bq'][] = '(is_review:true^100 OR is_review:false^0)';
    }
    

提交回复
热议问题