This repository has been archived by the owner on Apr 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
SearchlightBackend.inc
238 lines (209 loc) · 6.17 KB
/
SearchlightBackend.inc
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* Abstract class, defines interface for swappable search backends.
*/
abstract class SearchlightBackend {
var $id;
var $settings;
/**
* Constructor. Unpack backend variable & populate default settings.
*/
function __construct($id) {
$this->id = $id;
$this->settings = variable_get("searchlight_backend_{$this->id}", array()) + $this->settingsDefault();
// Allow drush to override any backend settings.
if (function_exists('drush_get_option')) {
foreach ($this->settings as $k => $v) {
$drush_option = drush_get_option('sl-' . str_replace('_', '-', $k));
if (isset($drush_option)) {
$this->settings[$k] = $drush_option;
}
}
}
}
/**
* Array of default settings for this search backend.
*/
function settingsDefault() {
return array();
}
/**
* System settings form for this search backend.
*/
function settingsForm($values) {
return array();
}
/**
* Views integration methods ================================================
*/
/**
* Backend callback for filter, argument views handler
* $handler->option_definition() method.
*/
function viewsOptionDefinition(&$handler) {
return array(
'hideEmpty' => array('default' => TRUE),
);
}
/**
* Backend callback for filter, argument views handler
* $handler->options_form() method.
*/
function viewsOptionsForm(&$form, &$form_state, &$handler) {
$form['hideEmpty'] = array(
'#title' => t('Hide all results when empty'),
'#type' => 'checkbox',
'#default_value' => $handler->options['hideEmpty'],
);
}
/**
* Backend callback for filter handler $handler->value_form() method.
*/
function viewsValueForm(&$form, &$form_state, &$handler) {
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Value'),
'#size' => 30,
'#default_value' => $handler->value,
);
if (isset($handler->options['expose']['identifier'])) {
$identifier = $handler->options['expose']['identifier'];
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
$form_state['input'][$identifier] = $handler->value;
}
}
}
/**
* Initialize a client for the search backend.
*
* @param $datasource
*/
function initClient($datasource) {
}
/**
* Execute a query using the search backend. Should return an array with the
* following keys:
*
* 'result': An array of base field IDs, e.g. nids.
* 'total': Total number of non-paged results.
* 'raw': The raw result object/array/data from the search client.
*/
function executeQuery(&$client, $datasource, $query = '') {
}
/**
* Set any custom options for the search backend.
*/
function setOptions(&$client, $datasource, $options) {
}
/**
* Set a filter parameter for the search backend.
*/
function setFilter(&$client, $datasource, $filters) {
}
/**
* Set a sort parameter for the search backend.
*/
function setSort(&$client, $datasource, $sorts) {
}
/**
* Set a pager/limit parameter for the search backend.
*/
function setPager(&$client, $offset, $limit) {
}
/**
* Set node_access attribute filters.
*/
function setNodeAccess(&$client) {
}
/**
* Utility date methods =====================================================
*/
/**
* Retrieve a from & to timestamps for a given granularity unit and base
* timestamp.
*/
function dateRange($timestamp, $granularity = 'month') {
switch ($granularity) {
case 'month':
$from = mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp));
$to = mktime(23, 59, 59, date('m', $timestamp), cal_days_in_month(CAL_GREGORIAN, date('m', $timestamp), date('Y', $timestamp)), date('Y', $timestamp));
break;
case 'day':
$from = mktime(0, 0, 0, date('m', $timestamp), date('d', $timestamp), date('Y', $timestamp));
$to = mktime(23, 59, 59, date('m', $timestamp), date('d', $timestamp), date('Y', $timestamp));
break;
case 'year':
$from = mktime(0, 0, 0, 1, 1, date('Y', $timestamp));
$to = mktime(23, 59, 59, 12, cal_days_in_month(CAL_GREGORIAN, 12, date('Y', $timestamp)), date('Y', $timestamp));
break;
}
return array('from' => $from, 'to' => $to);
}
/**
* Facet methods ============================================================
*/
/**
* Execute backend operations to determine the top facets for a given field.
*
* @return A result array, each with a sub-array of items containing:
*
* 'id': The primary ID for this item.
* 'count': The number of entries that belong to this facet item.
*/
function facetBuild(&$client, $datasource, $query = '', $facets) {
return array();
}
/**
* Build a views join and add it to view query to ensure only un-indexed
* content is returned.
*/
function queryFresh(&$sql_query) {
$join = new views_join();
$join->construct('searchlight_search', $sql_query->base_table, $sql_query->base_field, 'id', "searchlight_search.type = '{$sql_query->base_table}' AND searchlight_search.status = 0", 'INNER');
$sql_query->table_queue['searchlight_search'] = array(
'table' => 'searchlight_search',
'num' => 1,
'alias' => 'searchlight_search',
'join' => $join,
'relationship' => $sql_query->base_table,
);
}
/**
* Invalidate the search index associated with this datasource.
*/
function invalidateIndex($datasource) {
}
/**
* Drush methods ============================================================
*/
/**
* Start a search backend daemon process through drush.
*/
function drushSearchd($command = 'start') {
}
/**
* Start a search backend indexing process through drush.
*/
function drushIndex() {
}
/**
* Write search backend configuration files through drush.
*/
function drushConf() {
}
/**
* Execute functionality on a drush cron run.
*/
function drushCron() {
}
/**
* When a new site is installed via Aegir.
*/
function drushAegirInstall() {
}
/**
* When a site is migrated via Aegir.
*/
function drushAegirDeploy() {
}
}