Disable some processors when running

Created on 28 February 2024, 11 months ago
Updated 2 April 2024, 10 months ago

Problem/Motivation

We are running a Search API index with Highlight processor enabled. We have enabled autocomplete live results on this index, and we notice that the autocomplete dropdown takes a significant time to appear (~3 sec). Disabling the Highlight processor brings down the response time to an acceptable level (< 1 sec).

We only need the search results highlights when displaying the results on a page, but not in the autocomplete dropdown. We would like have the option to select which processors should be active during the autocomplete query run.

Steps to reproduce

- Create a search index
- Enable highlight processor
- Enable autocomplete live results
- Create a search view with a search filter and ensure autocomplete is enabled for that view
- Perform a search and observe the time needed to display the autocomplete dropdown
- Disable the highlight processor
- Perform a search and observe the time difference needed to display the autocomplete dropdown

Proposed resolution

- Allow the administrator to select which processors should be enabled / disabled on the autocomplete view page
- Expose a new hook that allows the developer to select which processor to enable and disable before a query run

User interface changes

On the Autocomplete view admin page, show all processors that are associated with the given index and allow to select/unselect them individually.

API changes

Expose a new hook search_api_autocomplete_processors_alter that accepts a modifiable list of processors.

Workaround

For now, we are using the hook hook_search_api_query_alter to capture queries with tag search_api_autocomplete. When found, we set their processing level to \Drupal\search_api\Query\QueryInterface::PROCESSING_BASIC which short-circuits the Highlight processor.

Feature request
Status

Active

Version

1.8

Component

Plugins

Created by

🇨🇦Canada infojunkie Vancouver

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

Comments & Activities

  • Issue created by @infojunkie
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for suggesting this new feature!

    It makes sense to skip highlighting if it is not needed, and especially if it takes such a long time in your case. (I’m pretty certain this is an outlier, I don’t think highlighting will typically take up 2/3 of the search request time.)
    However, if this is just about highlighting, then I’m not sure we really need this complex new functionality, since (as you have already noticed) setting the search query’s processing level to “basic” will already do exactly what you want. So maybe just a checkbox that says “Skip optional processing” (or something like that), explicitly mentioning highlighting in the description? (And no API change necessary.)

    Programmatically, I’m also not sure that temporarily changing the active processors from outside the Search API module will be that easy. And if it would be then the same might already be possible just using the existing hooks.

  • 🇦🇹Austria drunken monkey Vienna, Austria
  • 🇨🇦Canada infojunkie Vancouver

    Thanks for taking the time to review this.

    Yes, setting the processing level would address my particular use case, although I'm not sure about other users of your module.

    Maybe it's worth keeping this open to see if anyone else is interested, and if not, just close it as a one-off request whose workaround is documented.

  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺

    I think we have the same issue. @infojunkie Would it be possible to share the code you wrote for the workaround? Thank you.

  • 🇨🇦Canada infojunkie Vancouver

    Sure, here it is:

    function custom_module_search_api_query_alter($query) {
      if ($query->hasTag('search_api_autocomplete')) {
        // Set the processing level to basic to prevent highlighting processor from working during autocomplete queries.
        $query->setProcessingLevel(\Drupal\search_api\Query\QueryInterface::PROCESSING_BASIC);
      }
    }
    
  • 🇨🇦Canada phjou Vancouver 🇨🇦 🇪🇺

    @infojunkie Works like a charm! Thank you!

Production build 0.71.5 2024