Consider autocomplete JSON API endpoint

Created on 5 August 2024, 6 months ago
Updated 19 August 2024, 5 months ago

Problem/Motivation

For a headless search API implementation, there is a module https://www.drupal.org/project/jsonapi_search_api โ†’ . It would be a great addition if we could have a JSON API endpoint for the autocomplete as well.

Steps to reproduce

Proposed resolution

Provide a JSON API endpoint for the search autocomplete suggestion.

Remaining tasks

User interface changes

API changes

Data model changes

โœจ Feature request
Status

Postponed: needs info

Version

1.0

Component

Framework

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

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

Comments & Activities

  • Issue created by @prashant.c
  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria

    Iโ€™m not sure what exactly that would entail. The normal autocomplete already uses JSON when retrieving the autocomplete suggestions โ€“ would this new endpoint do the same, and just take the request parameters as JSON instead of as GET parameters?

  • Status changed to Postponed: needs info 5 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria
  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria

    Also, it seems like this might make more sense as an addition to the JSON:API Search API module โ†’ , not this one. But I might be mistaken. Probably depends on whether this would need to duplicate any of the code in that contrib module.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    @drunken monkey

    Thanks for the response.

    I have not gone through the code of search_api_autocompletemodule, but as you mentioned if it's already a REST API endpoint in the search_api_autocompletemodule then it will make more sense to add the JSON API resource in the JSON: API Search API module to extend it.

    Thanks, I will give it a try.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    I was going through the controllersearch_api_autocomplete/src/Controller/AutocompleteController.php, but does not look like it can act as a method to get JSON results simply because it is expecting arguments as SearchInterface $search_api_autocomplete_search and it seems expecting a view like an example request is search_api_autocomplete/search?display=page_1&filter=search_api_fulltext&q=different.

    My requirement is to just pass the search index, field(s) which could be only Fulltext indexed fields, and search string, and get the results in JSON format.

    Please suggest.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    It seems like https://www.drupal.org/project/search_api_decoupled โ†’ module is what could help me, will try this.

    Meanwhile, if you have any suggestions for the same please do let me know.

    Thanks

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria

    The Search API Autocomplete module wonโ€™t work if you have no search configured for it. Supported types of searches are search views and pages โ†’ , or anything else for which someone provides a \Drupal\search_api_autocomplete\Search\SearchPluginInterface plugin.

    So, itโ€™s not necessarily based on a view, but it needs to be based on something โ€“ you indeed canโ€™t just pass in the user input and get suggestions without any more setup.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Thanks for clarifying.

Production build 0.71.5 2024