search_api_solr.api.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Search API Solr search module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Lets modules alter a Solr search request before sending it.
  12. *
  13. * Apache_Solr_Service::search() is called afterwards with these parameters.
  14. * Please see this method for details on what should be altered where and what
  15. * is set afterwards.
  16. *
  17. * @param array $call_args
  18. * An associative array containing all four arguments to the
  19. * Apache_Solr_Service::search() call ("query", "offset", "limit" and
  20. * "params") as references.
  21. * @param SearchApiQueryInterface $query
  22. * The SearchApiQueryInterface object representing the executed search query.
  23. */
  24. function hook_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {
  25. if ($query->getOption('foobar')) {
  26. $call_args['params']['foo'] = 'bar';
  27. }
  28. }
  29. /**
  30. * Change the way the index's field names are mapped to Solr field names.
  31. *
  32. * @param $index
  33. * The index whose field mappings are altered.
  34. * @param array $fields
  35. * An associative array containing the index field names mapped to their Solr
  36. * counterparts. The special fields 'search_api_id' and 'search_api_relevance'
  37. * are also included.
  38. */
  39. function hook_search_api_solr_field_mapping_alter(SearchApiIndex $index, array &$fields) {
  40. if ($index->entity_type == 'node' && isset($fields['body:value'])) {
  41. $fields['body:value'] = 'text';
  42. }
  43. }
  44. /**
  45. * Lets modules alter the search results returned from a Solr search, based on
  46. * the original Solr response.
  47. *
  48. * @param array $results
  49. * The results array that will be returned for the search.
  50. * @param SearchApiQueryInterface $query
  51. * The SearchApiQueryInterface object representing the executed search query.
  52. * @param Apache_Solr_Response $response
  53. * The response object returned by Solr.
  54. */
  55. function hook_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, Apache_Solr_Response $response) {
  56. if (isset($response->facet_counts->facet_fields->custom_field)) {
  57. // Do something with $results.
  58. }
  59. }
  60. /**
  61. * Lets modules alter a Solr search request for a multi-index search before
  62. * sending it.
  63. *
  64. * Apache_Solr_Service::search() is called afterwards with these parameters.
  65. * Please see this method for details on what should be altered where and what
  66. * is set afterwards.
  67. *
  68. * @param array $call_args
  69. * An associative array containing all four arguments to the
  70. * Apache_Solr_Service::search() call ("query", "offset", "limit" and
  71. * "params") as references.
  72. * @param SearchApiMultiQueryInterface $query
  73. * The object representing the executed search query.
  74. */
  75. function hook_search_api_solr_multi_query_alter(array &$call_args, SearchApiMultiQueryInterface $query) {
  76. if ($query->getOption('foobar')) {
  77. $call_args['params']['foo'] = 'bar';
  78. }
  79. }
  80. /**
  81. * @} End of "addtogroup hooks".
  82. */