You are here

public static function Utility::getDataTypeInfo in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getDataTypeInfo()
  2. 8 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getDataTypeInfo()
  3. 8.2 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getDataTypeInfo()

Retrieves Solr-specific data for available data types.

Returns the data type information for the default Search API datatypes, the Solr specific data types and custom data types defined by hook_search_api_data_type_info(). Names for default data types are not included, since they are not relevant to the Solr service class.

We're adding some extra Solr field information for the default search api data types (as well as on behalf of a couple contrib field types). The extra information we're adding is documented in search_api_solr_hook_search_api_data_type_info(). You can use the same additional keys in hook_search_api_data_type_info() to support custom dynamic fields in your indexes with Solr.

Parameters

string|null $type: (optional) A specific type for which the information should be returned. Defaults to returning all information.

Return value

array|null If $type was given, information about that type or NULL if it is unknown. Otherwise, an array of all types. The format in both cases is the same as for search_api_get_data_type_info().

See also

search_api_get_data_type_info()

search_api_solr_hook_search_api_data_type_info()

2 calls to Utility::getDataTypeInfo()
SearchApiSolrBackend::extractResults in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Extract results from a Solr response.
SearchApiSolrBackend::formatSolrFieldNames in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Returns a language-specific mapping from Drupal to Solr field names.

File

src/Utility/Utility.php, line 55

Class

Utility
Provides various helper functions for Solr backends.

Namespace

Drupal\search_api_solr\Utility

Code

public static function getDataTypeInfo($type = NULL) {
  $types =& drupal_static(__FUNCTION__);
  if (!isset($types)) {

    // Grab the stock search_api data types.

    /** @var \Drupal\search_api\DataType\DataTypePluginManager $data_type_service */
    $data_type_service = \Drupal::service('plugin.manager.search_api.data_type');
    $types = $data_type_service
      ->getDefinitions();

    // Add our extras for the default search api fields.
    $types = NestedArray::mergeDeep($types, [
      'text' => [
        'prefix' => 't',
      ],
      'string' => [
        'prefix' => 's',
      ],
      'integer' => [
        // Use trie field for better sorting.
        'prefix' => 'it',
      ],
      'decimal' => [
        // Use trie field for better sorting.
        'prefix' => 'ft',
      ],
      'date' => [
        'prefix' => 'd',
      ],
      'duration' => [
        // Use trie field for better sorting.
        'prefix' => 'it',
      ],
      'boolean' => [
        'prefix' => 'b',
      ],
      'uri' => [
        'prefix' => 's',
      ],
    ]);

    // Extra data type info.
    $extra_types_info = [
      // Provided by Search API Location module.
      'location' => [
        'prefix' => 'loc',
      ],
      // @todo Who provides that type?
      'geohash' => [
        'prefix' => 'geo',
      ],
      // Provided by Search API Location module.
      'rpt' => [
        'prefix' => 'rpt',
      ],
    ];

    // For the extra types, only add our extra info if it's already been
    // defined.
    foreach ($extra_types_info as $key => $info) {
      if (array_key_exists($key, $types)) {

        // Merge our extras into the data type info.
        $types[$key] += $info;
      }
    }
  }

  // Return the info.
  if (isset($type)) {
    return $types[$type] ?? NULL;
  }
  return $types;
}