materio-base-legacy/search_api_solr.api.php
bachy c9912105d5 patch add custom field types
Signed-off-by: bachy <git@g-u-i.net>
2013-03-12 19:15:12 +01:00

130 lines
4.1 KiB
PHP

<?php
/**
* @file
* Hooks provided by the Search API Solr search module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Lets modules alter a Solr search request before sending it.
*
* Apache_Solr_Service::search() is called afterwards with these parameters.
* Please see this method for details on what should be altered where and what
* is set afterwards.
*
* @param array $call_args
* An associative array containing all four arguments to the
* Apache_Solr_Service::search() call ("query", "offset", "limit" and
* "params") as references.
* @param SearchApiQueryInterface $query
* The SearchApiQueryInterface object representing the executed search query.
*/
function hook_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {
if ($query->getOption('foobar')) {
$call_args['params']['foo'] = 'bar';
}
}
/**
* Change the way the index's field names are mapped to Solr field names.
*
* @param $index
* The index whose field mappings are altered.
* @param array $fields
* An associative array containing the index field names mapped to their Solr
* counterparts. The special fields 'search_api_id' and 'search_api_relevance'
* are also included.
*/
function hook_search_api_solr_field_mapping_alter(SearchApiIndex $index, array &$fields) {
if ($index->entity_type == 'node' && isset($fields['body:value'])) {
$fields['body:value'] = 'text';
}
}
/**
* Lets modules alter the search results returned from a Solr search, based on
* the original Solr response.
*
* @param array $results
* The results array that will be returned for the search.
* @param SearchApiQueryInterface $query
* The SearchApiQueryInterface object representing the executed search query.
* @param Apache_Solr_Response $response
* The response object returned by Solr.
*/
function hook_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, Apache_Solr_Response $response) {
if (isset($response->facet_counts->facet_fields->custom_field)) {
// Do something with $results.
}
}
/**
* Lets modules alter a Solr search request for a multi-index search before
* sending it.
*
* Apache_Solr_Service::search() is called afterwards with these parameters.
* Please see this method for details on what should be altered where and what
* is set afterwards.
*
* @param array $call_args
* An associative array containing all four arguments to the
* Apache_Solr_Service::search() call ("query", "offset", "limit" and
* "params") as references.
* @param SearchApiMultiQueryInterface $query
* The object representing the executed search query.
*/
function hook_search_api_solr_multi_query_alter(array &$call_args, SearchApiMultiQueryInterface $query) {
if ($query->getOption('foobar')) {
$call_args['params']['foo'] = 'bar';
}
}
/**
* 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".
*/