You are here

public static function Utility::getDataTypeInfo in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getDataTypeInfo()
  2. 8.2 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getDataTypeInfo()
  3. 4.x 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 both the default Search API 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()

1 call to Utility::getDataTypeInfo()
SearchApiSolrBackend::getSolrFieldNames in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Creates a list of all indexed field names mapped to their Solr field names.

File

src/Utility/Utility.php, line 40

Class

Utility
Utility functions specific to solr.

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, array(
      'text' => array(
        'prefix' => 't',
      ),
      'string' => array(
        'prefix' => 's',
      ),
      'integer' => array(
        // Use trie field for better sorting.
        'prefix' => 'it',
      ),
      'decimal' => array(
        // Use trie field for better sorting.
        'prefix' => 'ft',
      ),
      'date' => array(
        'prefix' => 'd',
      ),
      'duration' => array(
        // Use trie field for better sorting.
        'prefix' => 'it',
      ),
      'boolean' => array(
        'prefix' => 'b',
      ),
      'uri' => array(
        'prefix' => 's',
      ),
    ));

    // Extra data type info.
    $extra_types_info = array(
      // Provided by Search API Location module.
      'location' => array(
        'prefix' => 'loc',
      ),
      // @todo Who provides that type?
      'geohash' => array(
        '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 isset($types[$type]) ? $types[$type] : NULL;
  }
  return $types;
}