Copied from SearchApiAutocompleteInterface::getAutocompleteSuggestions(), this is currently the expected structure for a suggestion returned by a service class (and #2475435: Add support for switching the autocomplete implementation wouldn't change that):
prefix: For special suggestions, some kind of prefix describing them.suggestion_prefix: A suggested prefix for the entered input.user_input: The input entered by the user. Defaults to $user_input.suggestion_suffix: A suggested suffix for the entered input.results: If available, the estimated number of results for these keys.
This will then automatically be rendered with theme_search_api_autocomplete_suggestion(). In theory, it would be possible to override the theme function and definition to add more variables there and style them anyway you want, but I think we should provide a simpler solution for that.
When doing this, we could also make it possible to specify an URL to redirect to instead of a suggestion to search for – bringing us a lot closer to implementing #1567234: Merge with Search API Live results.
Finally, we should also make it possible to explicitly specify the autocompleted search terms instead of hard-coding this to suggestion_prefix + user_input + suggestion_suffix. The Solr implementation already adds a term key with exactly that, but I don't really know why since it's, at the moment, completely ignored (as far as I can tell).
For the technical implementation, I'd propose adding three new (optional) keys to suggestion structure:
render: If present, contains either HTML or a render array to show as the representation for this suggestion. Otherwise, the old variant is used.term: The complete input this suggestion should autocomplete to.url: Instead of being a suggestion, this should redirect to the given URL (which should be absolute). This is mutually exclusive withterm.
I don't really think term is the best key here, but I'd leave it like that to remain compatible with the existing Solr code.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2502937-5--follow_up_rename_term_to_keys.patch | 11.57 KB | drunken monkey |
| #1 | 2502937-1--additional_suggestion_keys.patch | 12.88 KB | drunken monkey |
Comments
Comment #1
drunken monkeyThis is a first version of the patch, based on #2475435-2: Add support for switching the autocomplete implementation (to avoid rebasing headaches later).
Comment #3
drunken monkeyComment #4
drunken monkeyCommitted.
Comment #5
drunken monkeyTurns out the
termkey in the Search API Solr module was introduced in #2034719: Improved autocomplete suggestions to provide back the filtered term and serves a different purpose, incompatible with this new definition.I'd therefore propose changing the
termkey tokeys, which I also think is more appropriate. Or any other wishes here?Patch attached. (Turns out I also blundered when committing this, adding a second
SearchApiAutocompleteSuggesterInterface.phpfile instead of changing the existing one with the new keys – so another reason for this follow-up.)Comment #6
drunken monkeyCommitted the follow-up.