apachesolr.interface.inc 14 KB

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