repatched for custom dynmaic field definition : https://drupal.org/node/1846860#comment-7805861
This commit is contained in:
parent
d8237ffb99
commit
62b7436183
@ -1,8 +1,79 @@
|
||||
diff --git a/includes/service.inc b/includes/service.inc
|
||||
index 4455235..20e57b8 100644
|
||||
--- a/includes/service.inc
|
||||
+++ b/includes/service.inc
|
||||
@@ -27,28 +27,6 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
protected $solr;
|
||||
|
||||
/**
|
||||
- * An array of all recognized types.
|
||||
- *
|
||||
- * Maps the type names to the prefixes used for identifying them in the Solr
|
||||
- * schema.
|
||||
- *
|
||||
- * @var array
|
||||
- */
|
||||
- protected static $type_prefixes = array(
|
||||
- 'text' => 'tm',
|
||||
- 'tokens' => 'tm',
|
||||
- 'string' => 's',
|
||||
- 'integer' => 'i',
|
||||
- 'decimal' => 'f',
|
||||
- 'date' => 'd',
|
||||
- 'duration' => 'i',
|
||||
- 'boolean' => 'b',
|
||||
- 'uri' => 's',
|
||||
- 'location' => 'loc',
|
||||
- 'geohash' => 'geo',
|
||||
- );
|
||||
-
|
||||
- /**
|
||||
* Static cache for getFieldNames().
|
||||
*
|
||||
* @var array
|
||||
@@ -290,7 +268,8 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
* Overrides SearchApiAbstractService::supportsFeature().
|
||||
*/
|
||||
public function supportsFeature($feature) {
|
||||
- $supported = drupal_map_assoc(array(
|
||||
+ // Search API features.
|
||||
+ $supported = array(
|
||||
'search_api_autocomplete',
|
||||
'search_api_facets',
|
||||
'search_api_facets_operator_or',
|
||||
@@ -300,7 +279,14 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
'search_api_spellcheck',
|
||||
'search_api_data_type_location',
|
||||
'search_api_data_type_geohash',
|
||||
- ));
|
||||
+ );
|
||||
+
|
||||
+ // Custom data types.
|
||||
+ foreach (search_api_solr_get_dynamic_field_info() as $type => $info) {
|
||||
+ $supported[] = 'search_api_data_type_' . $type;
|
||||
+ }
|
||||
+
|
||||
+ $supported = drupal_map_assoc($supported);
|
||||
return isset($supported[$feature]);
|
||||
}
|
||||
|
||||
@@ -495,8 +481,9 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
}
|
||||
|
||||
$inner_type = search_api_extract_inner_type($type);
|
||||
- $pref = isset(self::$type_prefixes[$inner_type]) ? self::$type_prefixes[$inner_type] : '';
|
||||
- if ($pref != 'tm') {
|
||||
+ $type_info = search_api_solr_get_dynamic_field_info($inner_type);
|
||||
+ $pref = isset($type_info['prefix']) ? $type_info['prefix']: '';
|
||||
+ if (empty($type_info['always multiValued'])) {
|
||||
$pref .= $type == $inner_type ? 's' : 'm';
|
||||
}
|
||||
if (!empty($this->options['clean_ids'])) {
|
||||
diff --git a/search_api_solr.api.php b/search_api_solr.api.php
|
||||
index f407407..ec4b190 100644
|
||||
index a64c477..cc9b208 100644
|
||||
--- a/search_api_solr.api.php
|
||||
+++ b/search_api_solr.api.php
|
||||
@@ -85,5 +85,45 @@ function hook_search_api_solr_multi_query_alter(array &$call_args, SearchApiMult
|
||||
@@ -101,5 +101,45 @@ function hook_search_api_solr_multi_query_alter(array &$call_args, SearchApiMult
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,15 +120,13 @@ index f407407..ec4b190 100644
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
||||
diff --git a/search_api_solr.module b/search_api_solr.module
|
||||
index 9e30397..b75319b 100644
|
||||
index cfab380..52ae956 100644
|
||||
--- a/search_api_solr.module
|
||||
+++ b/search_api_solr.module
|
||||
@@ -143,3 +143,81 @@ function search_api_solr_cron() {
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,84 @@ function search_api_solr_search_api_server_update(SearchApiServer $server) {
|
||||
}
|
||||
+
|
||||
+/**
|
||||
|
||||
/**
|
||||
+ * Returns either all dynamic field types, or a specific one.
|
||||
+ *
|
||||
+ * @param $type
|
||||
@ -113,93 +182,29 @@ index 9e30397..b75319b 100644
|
||||
+ 'always multiValued' => FALSE,
|
||||
+ ),
|
||||
+ 'duration' => array(
|
||||
+ 'i',
|
||||
+ 'prefix' => 'i',
|
||||
+ 'always multiValued' => FALSE,
|
||||
+ ),
|
||||
+ 'boolean' => array(
|
||||
+ 'b',
|
||||
+ 'prefix' => 'b',
|
||||
+ 'always multiValued' => FALSE,
|
||||
+ ),
|
||||
+ 'uri' => array(
|
||||
+ 's',
|
||||
+ 'prefix' => 's',
|
||||
+ 'always multiValued' => FALSE,
|
||||
+ ),
|
||||
+ 'location' => array(
|
||||
+ 'loc',
|
||||
+ 'prefix' => 'loc',
|
||||
+ 'always multiValued' => FALSE,
|
||||
+ ),
|
||||
+ 'geohash' => array(
|
||||
+ 'geohash',
|
||||
+ 'prefix' => 'geohash',
|
||||
+ 'always multiValued' => FALSE,
|
||||
+ ),
|
||||
+ );
|
||||
+}
|
||||
diff --git a/service.inc b/service.inc
|
||||
index 0e8dbee..5054c51 100644
|
||||
--- a/service.inc
|
||||
+++ b/service.inc
|
||||
@@ -18,26 +18,6 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
protected $solr;
|
||||
|
||||
/**
|
||||
- * An array of all recognized types mapped to a prefix used for identifying
|
||||
- * them in the Solr schema.
|
||||
- *
|
||||
- * @var array
|
||||
- */
|
||||
- protected static $type_prefixes = array(
|
||||
- 'text' => 'tm',
|
||||
- 'tokens' => 'tm',
|
||||
- 'string' => 's',
|
||||
- 'integer' => 'i',
|
||||
- 'decimal' => 'f',
|
||||
- 'date' => 'd',
|
||||
- 'duration' => 'i',
|
||||
- 'boolean' => 'b',
|
||||
- 'uri' => 's',
|
||||
- 'location' => 'loc',
|
||||
- 'geohash' => 'geohash',
|
||||
- );
|
||||
-
|
||||
- /**
|
||||
* @var array
|
||||
*/
|
||||
protected $fieldNames = array();
|
||||
@@ -222,7 +202,8 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
}
|
||||
|
||||
public function supportsFeature($feature) {
|
||||
- $supported = drupal_map_assoc(array(
|
||||
+ // Search API features.
|
||||
+ $supported = array(
|
||||
'search_api_autocomplete',
|
||||
'search_api_facets',
|
||||
'search_api_facets_operator_or',
|
||||
@@ -231,7 +212,14 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
'search_api_spellcheck',
|
||||
'search_api_data_type_location',
|
||||
'search_api_data_type_geohash',
|
||||
- ));
|
||||
+ );
|
||||
+
|
||||
+ // Custom data types.
|
||||
+ foreach (search_api_solr_get_dynamic_field_info() as $type => $info) {
|
||||
+ $supported[] = 'search_api_data_type_' . $type;
|
||||
+ }
|
||||
+
|
||||
+ $supported = drupal_map_assoc($supported);
|
||||
return isset($supported[$feature]);
|
||||
}
|
||||
|
||||
@@ -395,8 +383,9 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
}
|
||||
|
||||
$inner_type = search_api_extract_inner_type($type);
|
||||
- $pref = isset(self::$type_prefixes[$inner_type]) ? self::$type_prefixes[$inner_type] : '';
|
||||
- if ($pref != 'tm') {
|
||||
+ $type_info = search_api_solr_get_dynamic_field_info($inner_type);
|
||||
+ $pref = isset($type_info['prefix']) ? $type_info['prefix']: '';
|
||||
+ if (empty($type_info['always multiValued'])) {
|
||||
$pref .= $type == $inner_type ? 's' : 'm';
|
||||
}
|
||||
$name = $pref . '_' . $key;
|
||||
+/**
|
||||
* Retrieves a list of all config files of a server.
|
||||
*
|
||||
* @param SearchApiServer $server
|
@ -26,28 +26,6 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
*/
|
||||
protected $solr;
|
||||
|
||||
/**
|
||||
* An array of all recognized types.
|
||||
*
|
||||
* Maps the type names to the prefixes used for identifying them in the Solr
|
||||
* schema.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $type_prefixes = array(
|
||||
'text' => 'tm',
|
||||
'tokens' => 'tm',
|
||||
'string' => 's',
|
||||
'integer' => 'i',
|
||||
'decimal' => 'f',
|
||||
'date' => 'd',
|
||||
'duration' => 'i',
|
||||
'boolean' => 'b',
|
||||
'uri' => 's',
|
||||
'location' => 'loc',
|
||||
'geohash' => 'geo',
|
||||
);
|
||||
|
||||
/**
|
||||
* Static cache for getFieldNames().
|
||||
*
|
||||
@ -290,7 +268,8 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
* Overrides SearchApiAbstractService::supportsFeature().
|
||||
*/
|
||||
public function supportsFeature($feature) {
|
||||
$supported = drupal_map_assoc(array(
|
||||
// Search API features.
|
||||
$supported = array(
|
||||
'search_api_autocomplete',
|
||||
'search_api_facets',
|
||||
'search_api_facets_operator_or',
|
||||
@ -300,7 +279,14 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
'search_api_spellcheck',
|
||||
'search_api_data_type_location',
|
||||
'search_api_data_type_geohash',
|
||||
));
|
||||
);
|
||||
|
||||
// Custom data types.
|
||||
foreach (search_api_solr_get_dynamic_field_info() as $type => $info) {
|
||||
$supported[] = 'search_api_data_type_' . $type;
|
||||
}
|
||||
|
||||
$supported = drupal_map_assoc($supported);
|
||||
return isset($supported[$feature]);
|
||||
}
|
||||
|
||||
@ -495,8 +481,9 @@ class SearchApiSolrService extends SearchApiAbstractService {
|
||||
}
|
||||
|
||||
$inner_type = search_api_extract_inner_type($type);
|
||||
$pref = isset(self::$type_prefixes[$inner_type]) ? self::$type_prefixes[$inner_type] : '';
|
||||
if ($pref != 'tm') {
|
||||
$type_info = search_api_solr_get_dynamic_field_info($inner_type);
|
||||
$pref = isset($type_info['prefix']) ? $type_info['prefix']: '';
|
||||
if (empty($type_info['always multiValued'])) {
|
||||
$pref .= $type == $inner_type ? 's' : 'm';
|
||||
}
|
||||
if (!empty($this->options['clean_ids'])) {
|
||||
|
@ -100,6 +100,46 @@ function hook_search_api_solr_multi_query_alter(array &$call_args, SearchApiMult
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define how Search API Solr should index different data types.
|
||||
*
|
||||
* It is important to make sure that any types you define are also declared to
|
||||
* Search API using hook_search_api_data_type_info().
|
||||
*
|
||||
* @return array
|
||||
* An array containing data type definitions, keyed by their type identifier
|
||||
* and containing the following keys:
|
||||
* - prefix: The prefix used by the dynamic field type.
|
||||
* - always multiValued: (optional) Whether the single/multiple prefix should
|
||||
* be skipped for this data type. Defaults to FALSE.
|
||||
*
|
||||
* @see hook_search_api_solr_dynamic_field_info_alter()
|
||||
* @see search_api_solr_get_dynamic_field_info()
|
||||
* @see hook_search_api_data_type_info().
|
||||
*/
|
||||
function hook_search_api_solr_dynamic_field_info() {
|
||||
return array(
|
||||
'example_type' => array(
|
||||
'prefix' => 'ex',
|
||||
// Could be omitted, as FALSE is the default.
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the data type indexing info.
|
||||
*
|
||||
* @param array $infos
|
||||
* The item type info array, keyed by type identifier.
|
||||
*
|
||||
* @see hook_search_api_solr_dynamic_field_info()
|
||||
*/
|
||||
function hook_search_api_solr_dynamic_field_info_alter(array &$infos) {
|
||||
// Change the prefix used for example_type.
|
||||
$info['example_type']['prefix'] = 'ex2';
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
||||
|
@ -112,6 +112,84 @@ function search_api_solr_search_api_server_update(SearchApiServer $server) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either all dynamic field types, or a specific one.
|
||||
*
|
||||
* @param $type
|
||||
* If specified, the type whose definition should be returned.
|
||||
*
|
||||
* @return array
|
||||
* If $type was not given, an array containing all custom dynamic fields, in
|
||||
* the format specified by hook_search_api_solr_dynamic_field_info().
|
||||
* Otherwise, the definition for the given type, or NULL if it is unknown.
|
||||
*
|
||||
* @see hook_search_api_solr_dynamic_field_info().
|
||||
*/
|
||||
function search_api_solr_get_dynamic_field_info($type = NULL) {
|
||||
$types = &drupal_static(__FUNCTION__);
|
||||
if (!isset($types)) {
|
||||
$types = module_invoke_all('search_api_solr_dynamic_field_info');
|
||||
$types = $types ? $types : array();
|
||||
drupal_alter('search_api_solr_dynamic_field_info', $types);
|
||||
}
|
||||
if (isset($type)) {
|
||||
return isset($types[$type]) ? $types[$type] : NULL;
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_api_solr_dynamic_field_info().
|
||||
*/
|
||||
function search_api_solr_search_api_solr_dynamic_field_info() {
|
||||
return array(
|
||||
'text' => array(
|
||||
'prefix' => 'tm',
|
||||
'always multiValued' => TRUE,
|
||||
),
|
||||
'tokens' => array(
|
||||
'prefix' => 'tm',
|
||||
'always multiValued' => TRUE,
|
||||
),
|
||||
'string' => array(
|
||||
'prefix' => 's',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'integer' => array(
|
||||
'prefix' => 'i',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'decimal' => array(
|
||||
'prefix' => 'f',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'date' => array(
|
||||
'prefix' => 'd',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'duration' => array(
|
||||
'prefix' => 'i',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'boolean' => array(
|
||||
'prefix' => 'b',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'uri' => array(
|
||||
'prefix' => 's',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'location' => array(
|
||||
'prefix' => 'loc',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
'geohash' => array(
|
||||
'prefix' => 'geohash',
|
||||
'always multiValued' => FALSE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of all config files of a server.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user