public function SearchApiBaseFacetSource::getQueryTypesForDataType in Facets 8
Retrieves the query types for a specified data type.
Backend plugins can use this method to override the default query types provided by the Search API with backend-specific ones that better use features of that backend.
Parameters
\Drupal\search_api\Backend\BackendInterface $backend: The backend that we want to get the query types for.
string $data_type_plugin_id: The identifier of the data type.
Return value
string[] An associative array with the plugin IDs of allowed query types, keyed by the generic name of the query_type.
See also
hook_facets_search_api_query_type_mapping_alter()
2 calls to SearchApiBaseFacetSource::getQueryTypesForDataType()
- SearchApiBaseFacetSource::getFields in src/
Plugin/ facets/ facet_source/ SearchApiBaseFacetSource.php - Returns an array of fields that are defined on the facet source.
- SearchApiBaseFacetSource::getQueryTypesForFacet in src/
Plugin/ facets/ facet_source/ SearchApiBaseFacetSource.php - Returns the allowed query types for a given facet for the facet source.
File
- src/
Plugin/ facets/ facet_source/ SearchApiBaseFacetSource.php, line 172
Class
- SearchApiBaseFacetSource
- A base class for Search API facet sources.
Namespace
Drupal\facets\Plugin\facets\facet_sourceCode
public function getQueryTypesForDataType(BackendInterface $backend, $data_type_plugin_id) {
$query_types = [];
$query_types['string'] = 'search_api_string';
// Add additional query types for specific data types.
switch ($data_type_plugin_id) {
case 'date':
$query_types['date'] = 'search_api_date';
break;
case 'decimal':
case 'integer':
$query_types['numeric'] = 'search_api_granular';
$query_types['range'] = 'search_api_range';
break;
}
// Find out if the backend implemented the Interface to retrieve specific
// query types for the supported data_types.
if ($backend instanceof FacetsQueryTypeMappingInterface) {
// If the input arrays have the same string keys, then the later value
// for that key will overwrite the previous one. If, however, the arrays
// contain numeric keys, the later value will not overwrite the original
// value, but will be appended.
$query_types = array_merge($query_types, $backend
->getQueryTypesForDataType($data_type_plugin_id));
}
// Add it to a variable so we can pass it by reference. Alter hook complains
// due to the property of the backend object is not passable by reference.
$backend_plugin_id = $backend
->getPluginId();
// Let modules alter this mapping.
\Drupal::moduleHandler()
->alter('facets_search_api_query_type_mapping', $backend_plugin_id, $query_types);
return $query_types;
}