Problem/Motivation

Search API allows modules to provide backend-specific support for data types. SearchApiElasticsearchBackend does exactly this, defining a plugin to support the ObjectDataType. This module also provides a way to alter mappings.

In a recent project, I needed to add support for the Completion data type. I implemented the data type plugin and a processor plugin, and altered the mapping using hook_search_api_field_type_mapping_alter(). I also implemented an event subscriber to add my field mapping when the index is created.

This worked really well, except that Elasticsearch Connector marked the data type as unsupported. This is because SearchApiElasticsearchBackend has a method called supportsDataType() which checks to see if the provided type is in a hard-coded list of supported types. The only way around this I think is to patch SearchApiElasticsearchBackend.php to add in the other supported data types as needed.

Options

1. In SearchApiElasticsearchBackend::supportsDataType(), add an alter hook to allow sub-modules the chance to mark the data types that they provide as supported
2. Add direct support in elasticsearch_connector for the "completion" data type.
3. Don't hard the list of data types in the supportsDataType() method. Instead, add a method to the backend class that returns an array of supported data types, which calls the alter hook for sub-modules to extend that list. Then call this method in the supportsDataType() method.

Thoughts on direction?

Comments

ebeyrent created an issue. See original summary.

ebeyrent’s picture

Issue summary: View changes
ebeyrent’s picture

StatusFileSize
new2.66 KB

This is a rough patch, but kinda illustrates my idea. Open to ideas on this.

ebeyrent’s picture

StatusFileSize
new3.37 KB

Forgot to add a file

ebeyrent’s picture

StatusFileSize
new3.36 KB

And one more time to actually get the alter hook to get invoked properly.

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new3.32 KB

Re-rolling - for some reason composer wasn't apply to apply the last patch.

kevineinarsson’s picture

StatusFileSize
new3.34 KB

Patch re-rolled again

pySilver’s picture

  • skek committed 143b9a9 on 8.x-6.x authored by kevineinarsson
    Issue #3010114 by ebeyrent, pwolanin, kevineinarsson: Support Other Data...

  • skek committed a921190 on 8.x-7.x authored by kevineinarsson
    Issue #3010114 by ebeyrent, pwolanin, kevineinarsson: Support Other Data...
skek’s picture

Status: Needs review » Fixed

Thank you for the patch and collaboration on this issue.

@pySilver, thank you for pointing to the for you have worked on.
However the way Drupal community is working is by providing patches to the existing module, or if it is so different, it should be just a different module.
For example, the current issue is a good example how community work collaboratively to resolve an issue by providing problem/motivation and providing a patch that again the community can test and validate.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.