-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsearch_api_solr.api.php
166 lines (156 loc) · 5.8 KB
/
search_api_solr.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?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 \Solarium\QueryType\Update\Query\Document\Document[] $documents
* An array of \Solarium\QueryType\Update\Query\Document\Document objects
* ready to be indexed, generated from $items array.
* @param \Drupal\search_api\Index\IndexInterface $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, \Drupal\search_api\Index\IndexInterface $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';
}
}
/**
* Lets modules alter the search results returned from a multi-index search.
*
* @param array $results
* The results array that will be returned for the search.
* @param SearchApiMultiQueryInterface $query
* The executed multi-index search query.
* @param object $response
* The Solr response object.
*/
function hook_search_api_solr_multi_search_results_alter(array &$results, SearchApiMultiQueryInterface $query, $response) {
if (isset($response->facet_counts->facet_fields->custom_field)) {
// Do something with $results.
}
}
/**
* Provide Solr dynamic fields as Search API data types.
*
* This serves as a placeholder for documenting additional keys for
* hook_search_api_data_type_info() which are recognized by this module to
* automatically support dynamic field types from the schema.
*
* @return array
* In addition to the keys for the individual types that are defined by
* hook_search_api_data_type_info(), the following keys are regonized:
* - prefix: The Solr field name prefix to use for this type. Should match
* two existing dynamic fields definitions with names "{PREFIX}s_*" and
* "{PREFIX}m_*".
* - always multiValued: (optional) If TRUE, only the dynamic field name
* prefix (without the "_*" portion) with multiValued="true" should be given
* by "prefix", instead of the common prefix part for both the single-valued
* and the multi-valued field. This should be the case for all fulltext
* fields, since they might already be tokenized by the Search API. Defaults
* to FALSE.
*
*@see hook_search_api_data_type_info()
*/
function search_api_solr_hook_search_api_data_type_info() {
return array(
// You can use any identifier you want here, but it makes sense to use the
// field type name from schema.xml.
'edge_n2_kw_text' => array(
// Stock hook_search_api_data_type_info() info:
'name' => t('Fulltext (w/ partial matching)'),
'fallback' => 'text',
// Dynamic field with name="te_*".
'prefix' => 'te',
// Fulltext types should always be multi-valued.
'always multiValued' => TRUE,
),
'tlong' => array(
// Stock hook_search_api_data_type_info() info:
'name' => t('TrieLong'),
'fallback' => 'integer',
// Dynamic fields with name="its_*" and name="itm_*".
'prefix' => 'it',
),
);
}
/**
* @} End of "addtogroup hooks".
*/