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.
Comments
Comment #2
infojunkieComment #3
drunken monkeyThanks 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.
Comment #4
drunken monkeyComment #5
infojunkieComment #6
infojunkieThanks 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.
Comment #7
phjouI think we have the same issue. @infojunkie Would it be possible to share the code you wrote for the workaround? Thank you.
Comment #8
infojunkieSure, here it is:
Comment #9
phjou@infojunkie Works like a charm! Thank you!
EDIT: Oh just noticed that you are in Vancouver too.