Allow modules to extend SearchApiFacetapiAdapter class

Created on 29 July 2024, 5 months ago
Updated 3 August 2024, 5 months ago

Problem/Motivation

I implemented hook_facetapi_adapters to provide my own adapter that extends the SearchApiFacetapiAdapter, and then used hook_facetapi_searcher_info_alter to alter the adapter, e.g.,

if ($info['instance'] == 'my_index') {
  $info['adapter'] = 'my_adapter';
}

It is not working at the moment because search_api_facetapi_facetapi_facet_info is doing:

if ('search_api' == $searcher_info['adapter']) {<br>
}

I think it should be checking the module instead as we are able to swap the adapter, e.g.,

if ('search_api_facetapi' == $searcher_info['module']) {<br>
}
✨ Feature request
Status

Needs review

Version

1.29

Component

Facets

Created by

🇺🇸United States xlin1003

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

Comments & Activities

  • Issue created by @xlin1003
  • 🇺🇸United States xlin1003
  • 🇺🇸United States xlin1003

    Add similar issue in apachesolr.

  • Status changed to Needs review 5 months ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for reporting this problem!
    However, I’m not 100% sure about your solution. It might be what you want, but in general it doesn’t seem guaranteed that someone implementing their own adapter would still want us to provide the facet info. Also, at this point, I’m extremely hesitant to change any behavior in my Drupal 7 code, especially to add features.
    But feel free to either just keep this patch applied to your code, or use a workaround like this:

    /**
     * Implements hook_facetapi_facet_info().
     */
    function my_module_facetapi_facetapi_facet_info(array $searcher_info) {
      // Masquerade our adapter as the "search_api" adapter.
      if ($searcher_info['adapter'] === 'my_adapter') {
        $searcher_info['adapter'] = 'search_api';
        return search_api_facetapi_facetapi_facet_info($searcher_info);
      }
      return array();
    }
    

    Still, leaving open in case this is a more popular request than I thought.

Production build 0.71.5 2024