Search API Endpoint

Last updated on
8 February 2024

After you have added search server, index, facets (optional) and autocomplete settings (optional), now it is time to create your first search endpoint.

Search endpoint is a config entity that stores information on how the search could be performed on the given index, with given facets and autocomplete settings (in case the modules are installed).

Search endpoint overview page is located here /admin/config/search/search-api/endpoints ("Configuration -> "Search and metadata" -> "Search API" -> "Endpoints"). There it is possible to manage (add/edit/delete) endpoints.

Search API Endpoints overview page

Config properties

The main setting for the endpoint is of course "Search Index". In the list you will find all the indexes, that were created with help of Search API module. Among other important settings is the "Parse mode". Search API provides the plugins for parsing the search keywords. This list can be extended with contrib and custom plugins.

There are also settings for number of items served per page and default sorting or results. Moreover, it is possible to allow users to change number of items per page, but also control what options they have.

Search API Endpoint add/edit form

UI Elements

If search_api_decoupled_ui submodule is enabled, there is "UI elements" tab, that has settings for the search block display. It is possible to select search display layout and also place search UI elements to any region of the layout:

UI Elements page

Layouts

Layouts are provided by Drupal core module "Layout Discovery". This module also ships 3 basic layouts: "One column", "Two columns" and "Three columns". Layouts are defined in module's .layouts.yml file. It is possible to create your own layouts in custom module or theme. This modules filters layouts by category "Search". This way to have your own layout available you need to add category: 'Search' in layout definition.

Standard Layouts Description

  1. One column layout has only one region "Content". All UI elements will be added to it.
  2. Two columns layout consists of 4 regions: "Top", "First" (middle left), "Second" (middle right) and "Bottom".
  3. Three columns layout consists of 5 regions: "Top", "First" (middle left), "Second" (middle center), "Third" (middle right) and "Bottom".

Using Endpoint

Each search endpoint has its own access control with permission. This way some of them can be available only for certain user roles.

The endpoint route is: GET /api/search/{search_api_endpoint}, where {search_api_endpoint} is the machine name of Search API Endpoint.

Filters

  1. Main filter is full text search filter. To search for words query parameter q should be used.
  2. It is possible to filter by any non full text fields of the index by just passing field name to query parameters, e.g. nid=10. It is also possible to have array values like nid[]=10&nid[]=11.
  3. Faceted search uses query parameter f or any other that is set in the facet source configuration. To search by facet one needs to use following query parameters f[0]=facet_name:filter_value&f[1]=another_facet_name:another_facet_value
  4. It is also possible to sort by any index field in both asc and desc order. For sorting sort query parameter is used, for order of sorting - order.
  5. Pagination starts with page 0 and can be controlled with page query parameter. It is also possible to pass limit parameter to control number of items per page. For this configuration of endpoint should allow it and provide the options to select from (free choice is not allowed).

Example:

Request GET /api/search/default?q=drupal&sort=nid&f[0]=date:2021-12

Help improve this page

Page status: No known problems

You can: