| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | <?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 three arguments to the *   SearchApiSolrConnectionInterface::search() call ("query", "params" and *   "method") 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 SearchApiIndex $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';  }}/** * Alter Solr documents before they are sent to Solr for indexing. * * @param array $documents *   An array of SearchApiSolrDocument objects ready to be indexed, generated *   from $items array. * @param SearchApiIndex $index *   The search index for which items are being indexed. * @param array $items *   An array of items being indexed. */function hook_search_api_solr_documents_alter(array &$documents, SearchApiIndex $index, array $items) {  // Adds a "foo" field with value "bar" to all documents.  foreach ($documents as $document) {    $document->setField('foo', 'bar');  }}/** * Lets modules alter the search results returned from a Solr search. * * @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 object $response *   The Solr response object. */function hook_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, $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. * * SearchApiSolrConnectionInterface::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 three arguments to the *   SearchApiSolrConnectionInterface::search() call ("query", "params" and *   "method") 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". */
 |