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?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3010114-7.patch | 3.34 KB | kevineinarsson |
| #6 | 3010114-6.patch | 3.32 KB | pwolanin |
| #5 | support-other-data-types-3010114-5.patch | 3.36 KB | ebeyrent |
| #4 | support-other-data-types-3010114-4.patch | 3.37 KB | ebeyrent |
| #3 | support-other-data-types-3010114-3.patch | 2.66 KB | ebeyrent |
Comments
Comment #2
ebeyrent commentedComment #3
ebeyrent commentedThis is a rough patch, but kinda illustrates my idea. Open to ideas on this.
Comment #4
ebeyrent commentedForgot to add a file
Comment #5
ebeyrent commentedAnd one more time to actually get the alter hook to get invoked properly.
Comment #6
pwolanin commentedRe-rolling - for some reason composer wasn't apply to apply the last patch.
Comment #7
kevineinarsson commentedPatch re-rolled again
Comment #8
pySilver commentedAll datatypes are supported at: https://www.drupal.org/project/elasticsearch_connector/issues/3077463
Comment #11
skek commentedThank 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.