comparison sites/all/modules/custom/solrconnect/apachesolr.interface.inc @ 0:015d06b10d37 default tip

initial
author dwinter
date Wed, 31 Jul 2013 13:49:13 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:015d06b10d37
1 <?php
2
3 /**
4 * The interface for all 'query' objects.
5 */
6 interface DrupalSolrQueryInterface {
7
8 /**
9 * Get query name.
10 */
11 function getName();
12
13 /**
14 * Get query searcher name (for facetapi, views, pages, etc).
15 */
16 function getSearcher();
17
18 /**
19 * Get context values.
20 */
21 function getContext();
22
23 /**
24 * Set context value.
25 */
26 function addContext(array $context);
27
28 /**
29 * Returns all filters matching $name, if set; otherwise, returns all filters.
30 *
31 * @param string $name
32 * The facet field name to match. If NULL, all filters will be returned.
33 *
34 * @return array
35 * All matching filters.
36 */
37 function getFilters($name = NULL);
38
39 /**
40 * Tests whether a filter is already present in the query.
41 *
42 * @param string $name
43 * The facet field name to check.
44 * @param string $value
45 * The facet value to check.
46 * @param boolean $exclude
47 * Optional, defaults to FALSE, must match the filter.
48 *
49 * @return boolean
50 * TRUE or FALSE.
51 */
52 function hasFilter($name, $value, $exclude = FALSE);
53
54 /**
55 * Adds a filter to the query.
56 *
57 * @param string $name
58 * The facet field name.
59 * @param string $value
60 * The facet field value.
61 * @param boolean $exclude
62 * Set to TRUE to filter out documents matching $value.
63 * @param string $local
64 * Solr LocalParams.
65 *
66 * @return DrupalSolrQueryInterface
67 * The called object.
68 */
69 function addFilter($name, $value, $exclude = FALSE, $local = '');
70
71 /**
72 * Removes a filter from the query.
73 *
74 * @param string $name
75 * The name of the facet field to remove.
76 * @param string $value
77 * The value of the facet field to remove. If NULL, all filters matching
78 * $name are removed.
79 * @param boolean $exclude
80 * If $value is not NULL, only filters matching both $value and $exclude are
81 * removed. Ignored if $value is NULL.
82 *
83 * @return DrupalSolrQueryInterface
84 * The called object.
85 */
86 function removeFilter($name, $value = NULL, $exclude = FALSE);
87
88 /**
89 * Returns all subqueries to the query.
90 *
91 * @return array
92 * All subqueries to the query.
93 */
94 function getFilterSubQueries();
95
96 /**
97 * Adds a subquery to the query.
98 *
99 * @param SolrFilterSubQuery $query
100 * The query to add to the orginal query - may have keywords or filters.
101 * @param string $fq_operator
102 * The operator to use within the filter part of the subquery
103 * @param string $q_operator
104 * The operator to use in joining the subquery to the main keywords. Note:
105 * this is unlikely to work with the Dismax handler when the main query is
106 * only keywords.
107 *
108 * @return DrupalSolrQueryInterface
109 * The called object.
110 */
111 function addFilterSubQuery(SolrFilterSubQuery $query);
112
113 /**
114 * Removes a specific subquery.
115 *
116 * @param DrupalSolrQueryInterface $query
117 * The query to remove.
118 *
119 * @return DrupalSolrQueryInterface
120 * The called object.
121 */
122 function removeFilterSubQuery(SolrFilterSubQuery $query);
123
124 /**
125 * Removes all subqueries.
126 *
127 * @return DrupalSolrQueryInterface
128 * The called object.
129 */
130 function removeFilterSubQueries();
131
132 /**
133 * Transforms a single filter in a form suitable for use in a Solr query.
134 *
135 * @param array $filter
136 * A filter as an array with the keys '#name', for the facet field name,
137 * '#value', for the facet field value, '#local', for Solr LocalParams, and
138 '#exclude' set to TRUE if it is an exclusion filter.
139 *
140 * @return string
141 * A Solr fq parameter value.
142 */
143 function makeFilterQuery(array $filter);
144
145 /**
146 * Gets the value of a parameter.
147 *
148 * @param string $name
149 * The parameter name.
150 *
151 * @return
152 * The value of the parameter.
153 */
154 function getParam($name);
155
156 /**
157 * Gets all parameters in normalized form.
158 *
159 * @return array
160 * All parameters as key-value pairs.
161 */
162 function getParams();
163
164 /**
165 * Gets parameters in a form suitable for use in a Solr query.
166 *
167 * @return array
168 * All parameters as key-value pairs, where values have been transformed
169 * into Solr parameter values.
170 */
171 function getSolrParams();
172
173 /**
174 * Adds a param to be sent when running the Solr search.
175 *
176 * If the param is single-valued, this will replace rather than add the value.
177 *
178 * @param string $name
179 * A Solr param name, e.g. 'q' or 'fl'.
180 * @param $value
181 * A Solr param value: an array of values, or a string for a single value.
182 *
183 * @return DrupalSolrQueryInterface
184 * The called object.
185 */
186 function addParam($name, $value);
187
188 /**
189 * Adds multiple params to be sent when running the Solr search.
190 *
191 * If the param is single-valued, this will replace rather than add the value.
192 *
193 * @param $params
194 * An array where the keys are param names, and the values may be strings or
195 * arrays of strings.
196 *
197 * @return DrupalSolrQueryInterface
198 * The called object.
199 */
200 function addParams(array $params);
201
202 /**
203 * Removes all values for one Solr param.
204 *
205 * @param string $name
206 * A Solr param name, e.g. 'q' or 'fl'.
207 *
208 * @return DrupalSolrQueryInterface
209 * The called object.
210 */
211 function removeParam($name);
212
213 /**
214 * Replaces a param to be sent when running the Solr search.
215 *
216 * Basically a shortcut for removeParam() plus addParam().
217 *
218 * @param string $name
219 * A Solr param name, e.g. 'q' or 'fl'.
220 * @param $value
221 * A Solr param value: an array of values, or a string for a single value.
222 *
223 * @return DrupalSolrQueryInterface
224 * The called object.
225 */
226 function replaceParam($name, $value);
227
228 /**
229 * Handles aliases for field to make nicer URLs.
230 *
231 * @param $field_map
232 * An array keyed with real Solr index field names with the alias as value.
233 *
234 * @return DrupalSolrQueryInterface
235 * The called object.
236 */
237 function addFieldAliases($field_map);
238
239 function getFieldAliases();
240
241 function clearFieldAliases();
242
243 function getAvailableSorts();
244
245 /**
246 * Adds an available sort.
247 *
248 * @param string $name
249 * The name of the field in the Solr index to sort on.
250 * @param array $sort
251 * An array with the keys 'title', for the human name of the sort, and
252 * 'default', for the default sort direction ('asc' or 'desc').
253 *
254 * @return DrupalSolrQueryInterface
255 * The called object.
256 */
257 function setAvailableSort($name, $sort);
258
259 /**
260 * Removes an available sort.
261 *
262 * @param string $name
263 * The name of the field in the Solr index to sort on.
264 *
265 * @return DrupalSolrQueryInterface
266 * The called object.
267 */
268 function removeAvailableSort($name);
269
270 /**
271 * Gets the current sort.
272 *
273 * @return array
274 * The current sort as an array with the keys '#name', for the name of
275 * the field, and '#direction', for the sort direction ('asc' or 'desc').
276 */
277 function getSolrsort();
278
279 /**
280 * Sets the sort.
281 *
282 * @param string $field
283 * The name of the field in the Solr index to sort on.
284 * @param string $direction
285 * 'asc' or 'desc'
286 *
287 * @return DrupalSolrQueryInterface
288 * The called object.
289 */
290 function setSolrsort($name, $direction);
291
292 /**
293 * Returns an array representing the URL query string for the current sort.
294 *
295 * @return array
296 * The URL query string for the current sort.
297 */
298 function getSolrsortUrlQuery();
299
300 /**
301 * Returns the search path (including the search keywords).
302 *
303 * @param string $new_keywords
304 * Optional. When set, this string overrides the query's current keywords.
305 *
306 * @return string
307 * The search path.
308 */
309 function getPath($new_keywords = NULL);
310
311 /**
312 * Sends the search request to Solr, unless $query->abort_search is TRUE.
313 *
314 * @param string $keys
315 * The search keys.
316 *
317 * @return
318 * A stdClass response object.
319 */
320 function search($keys = NULL);
321
322 /**
323 * Calls a method, without arguments, on the Solr object with which the query
324 * object was initialized.
325 *
326 * @param string $method
327 * The method to call on the Solr object.
328 *
329 * @return
330 * Any method return.
331 */
332 function solr($method);
333 }
334
335 /**
336 * The interface for all 'Service' objects.
337 */
338 interface DrupalApacheSolrServiceInterface {
339 /**
340 * Call the /admin/ping servlet, to test the connection to the server.
341 *
342 * @param $timeout
343 * maximum time to wait for ping in seconds, -1 for unlimited (default 2).
344 * @return
345 * (float) seconds taken to ping the server, FALSE if timeout occurs.
346 */
347 function ping($timeout = 2);
348
349 /**
350 * Get information about the Solr Core.
351 *
352 * @return
353 * (string) system info encoded in json
354 */
355 function getSystemInfo();
356
357 /**
358 * Get just the field meta-data about the index.
359 */
360 function getFields($num_terms = 0);
361
362 /**
363 * Get meta-data about the index.
364 */
365 function getLuke($num_terms = 0);
366
367 /**
368 * Get information about the Solr Core.
369 *
370 * Returns a Simple XMl document
371 */
372 function getStats();
373
374 /**
375 * Get summary information about the Solr Core.
376 */
377 function getStatsSummary();
378
379 /**
380 * Clear cached Solr data.
381 */
382 function clearCache();
383
384 /**
385 * Constructor
386 *
387 * @param $url
388 * The URL to the Solr server, possibly including a core name. E.g. http://localhost:8983/solr/
389 * or https://search.example.com/solr/core99/
390 * @param $env_id
391 * The machine name of a corresponding saved configuration used for loading
392 * data like which facets are enabled.
393 */
394 function __construct($url, $env_id = NULL);
395
396 function getId();
397
398 /**
399 * Make a request to a servlet (a path) that's not a standard path.
400 *
401 * @param string $servlet
402 * A path to be added to the base Solr path. e.g. 'extract/tika'
403 *
404 * @param array $params
405 * Any request parameters when constructing the URL.
406 *
407 * @param array $options
408 * @see drupal_http_request() $options.
409 *
410 * @return
411 * response object
412 *
413 * @thows Exception
414 */
415 function makeServletRequest($servlet, $params = array(), $options = array());
416
417 /**
418 * Get the Solr url
419 *
420 * @return string
421 */
422 function getUrl();
423
424 /**
425 * Set the Solr url.
426 *
427 * @param $url
428 *
429 * @return $this
430 */
431 function setUrl($url);
432
433 /**
434 * Raw update Method. Takes a raw post body and sends it to the update service. Post body
435 * should be a complete and well formed xml document.
436 *
437 * @param string $rawPost
438 * @param float $timeout Maximum expected duration (in seconds)
439 *
440 * @return response object
441 *
442 * @throws Exception If an error occurs during the service call
443 */
444 function update($rawPost, $timeout = FALSE);
445
446 /**
447 * Add an array of Solr Documents to the index all at once
448 *
449 * @param array $documents Should be an array of ApacheSolrDocument instances
450 * @param boolean $allowDups
451 * @param boolean $overwritePending
452 * @param boolean $overwriteCommitted
453 *
454 * @return response objecte
455 *
456 * @throws Exception If an error occurs during the service call
457 */
458 function addDocuments($documents, $overwrite = NULL, $commitWithin = NULL);
459
460 /**
461 * Send a commit command. Will be synchronous unless both wait parameters are set to false.
462 *
463 * @param boolean $optimize Defaults to true
464 * @param boolean $waitFlush Defaults to true
465 * @param boolean $waitSearcher Defaults to true
466 * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
467 *
468 * @return response object
469 *
470 * @throws Exception If an error occurs during the service call
471 */
472 function commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600);
473
474 /**
475 * Create a delete document based on document ID
476 *
477 * @param string $id Expected to be utf-8 encoded
478 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
479 *
480 * @return response object
481 *
482 * @throws Exception If an error occurs during the service call
483 */
484 function deleteById($id, $timeout = 3600);
485
486 /**
487 * Create and post a delete document based on multiple document IDs.
488 *
489 * @param array $ids Expected to be utf-8 encoded strings
490 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
491 *
492 * @return response object
493 *
494 * @throws Exception If an error occurs during the service call
495 */
496 function deleteByMultipleIds($ids, $timeout = 3600);
497
498 /**
499 * Create a delete document based on a query and submit it
500 *
501 * @param string $rawQuery Expected to be utf-8 encoded
502 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
503 * @return stdClass response object
504 *
505 * @throws Exception If an error occurs during the service call
506 */
507 function deleteByQuery($rawQuery, $timeout = 3600);
508
509 /**
510 * Send an optimize command. Will be synchronous unless both wait parameters are set
511 * to false.
512 *
513 * @param boolean $waitFlush
514 * @param boolean $waitSearcher
515 * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
516 *
517 * @return response object
518 *
519 * @throws Exception If an error occurs during the service call
520 */
521 function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600);
522
523 /**
524 * Simple Search interface
525 *
526 * @param string $query The raw query string
527 * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
528 *
529 * @return response object
530 *
531 * @throws Exception If an error occurs during the service call
532 */
533 function search($query = '', array $params = array(), $method = 'GET');
534
535 /**
536 * Get the current solr version. This could be 1, 3 or 4
537 *
538 * @return int
539 * 1, 3 or 4. Does not give a more details version, for that you need
540 * to get the system info.
541 */
542 function getSolrVersion();
543
544 }