I have defined a custom drupal fieldtype (not a search api custom field!) whose schema has two separate value fields (let's call them value_a and value_b). I also have a node type that is my indexed entity for a solr search, and this node type has a multi-value field of my custom fieldtype.
I'm currently able to index the component values of the field just fine. However, I want to explicitly index the field instance values as pairs. So if I search for value_a = "foo" and value_b = "bar", I only want those nodes who have foo and bar on the same delta.
I noticed that my field appears in the section at the bottom of the Add Fields to Index page, under the text that says "The following fields cannot be indexed since there is no type mapping for them"
Is it possible to define a type mapping for my custom field? I'd like the field values to be indexed together (foo+bar), rather than individually.
Comments
Comment #2
mkalkbrennerThis is a Search API question.
Comment #3
drunken monkeyIt is possible to add a mapping for your type, via the
\Drupal\search_api\Event\SearchApiEvents::MAPPING_FIELD_TYPESevent (see there and\Drupal\search_api\Utility\DataTypeHelper::getFieldTypeMapping()). However, no existing type can (probably) handle your data type, so you’d also need to add a new Search API data type (see\Drupal\search_api\DataType\DataTypePluginBaseand the docs) – and then you’d need to bring the Solr backend to actually recognize your new Search API data type, which I’m not sure how to do currently. (It used to be that you could just add a few properties to the data type plugin definition, but that doesn’t seem to be the case anymore?)All in all, I think the better solution would be to add a processor that provides the data exactly the way you want it as a custom property. Then you can just index the values as, e.g.,
'foo--bar'and filter accordingly at search time.