This module provides a way to easily created faceted search pages. Depends on search_api and elasticsearch_connector to index content.
This module provides a framework to set up custom Elasticsearch based search pages.
Features:
- Ajax powered faceted search
- Synonyms
- Autocompletion
- Search suggestions
It depends on search_api to manage your indexed data and elasticsearch_connector to set up a connection
with your Elasticsearch backend.
The elasticsearch_search_api module provides services, interfaces, Controllers and Classes to help you set up
custom Elasticsearch search pages, including the option to add facets, modify the search query that is sent to Elastic, add different search suggesters and analysers to fields (for example: n-gram) or add different searching
'strategies' to your Elasticsearch index.
Out-of-the box the module provides the ability to add autosuggestion, did-you-mean functionality,
synonyms and a strategy to copy all your indexed field data into a 'custom_all' text based field.
The idea of this module is to use it as a framework when building your own custom search module.
There is a lot of functionality that is included in the base module, but in your own search implementation,
services, controllers, templates, etc can be extended or extra searching strategies can be added to fit your needs.
## Installation
@@ -31,9 +39,10 @@ Add both this module and the block ui library to your project's composer.json, w
```
And install it as usual: `composer require drupal/elasticsearch_search_api`
### Example module
### Example module elasticsearch_search_api_example
Submodule elasticsearch_search_api_example - should only be used as a demo.
The base module has a submodule, elasticsearch_search_api_example. This submodule is intended as a demo
of a custom elasticsearch implementation or as a reference point when starting your own custom implementation.
#### Installation steps
@@ -47,10 +56,197 @@ Submodule elasticsearch_search_api_example - should only be used as a demo.
To create content to populate the example search, add some "Elasticsearch page" nodes.
Facets are activated, they can be used by creating "page_type" taxonomy terms. These can be referenced on "Elasticsearch page" content.
## Usage
### Routes & Controllers
This module should be used as a starting point for your own custom search implementation. It provides services that handle the communication between
Drupal and the ElasticSearch backend.
You can take a look at the elasticsearch_search_api_example module as a reference on how to start building your own custom search module.
## Services
The base module has a services.yml.example file. Each custom search implementation should define its own services.yml file and define what services should be used
The params builder service builds the parameters for the search action that we send to the elasticsearch backend. This service builds an array that will be converted
to JSON and sent over to the elasticsearch backend.
Event subscriber that triggers on the PREPARE_INDEX and PREPARE_INDEX_MAPPING events sent out by
the elasticsearch_connector module.
In the base module, this event subscriber is used to add an ngram tokenizer and analyser to the index
configuration.
By default, this added ngram analyzer is also added to the 'title' (entity title) field.
More info about n-gram tokenizers within ElasticSearch can be found on: https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html
## Routes & Controllers
A search results page typically needs two routes/callbacks:
- search callback to render the search page on page loads
@@ -109,7 +305,7 @@ class MyCustomController extends SearchController {
}
```
### Facets
## Facets
Creating and using facets requires the following:
- an instance of `Drupal\elasticsearch_search_api\Search\Facet\Control\CompositeFacetControlInterface` or `Drupal\elasticsearch_search_api\Search\Facet\Control\FacetControlInterface`
@@ -146,9 +342,75 @@ class RegionFacetControl extends TermFacetBase {
}
```
### ParamsBuilder
## Searching strategies
The base module has a SyncStrategy base class and a SyncService. These are used to add custom
searching strategies to your ElasticSearch index.
The SyncStrategy base class should be extended by your custom search strategies.
The SyncService is used to alter the index settings and field mapping to add these searching strategies
to your index.
```
public function execute(ClientInterface $client, array $settingsParams = [], array $mappingParams = []) {