solr_connection.interface.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <?php
  2. /**
  3. * The interface for a Solr connection class.
  4. */
  5. interface SearchApiSolrConnectionInterface {
  6. /**
  7. * Constructs a Solr connection objects.
  8. *
  9. * @param array $options
  10. * An array containing construction arguments.
  11. */
  12. public function __construct(array $options);
  13. /**
  14. * Calls the /admin/ping servlet, to test the connection to the server.
  15. *
  16. * @param int|false $timeout
  17. * Maximum time to wait for ping in seconds, -1 for unlimited (default 2).
  18. *
  19. * @return float|false
  20. * Seconds taken to ping the server, FALSE if timeout occured.
  21. */
  22. public function ping($timeout = 2);
  23. /**
  24. * Sets whether this connection will use soft commits when comitting.
  25. *
  26. * Note that this setting only has any effect when using Solr 4.x or higher.
  27. *
  28. * @param $soft_commit
  29. * TRUE if soft commits should be used, FALSE otherwise. Default is FALSE.
  30. */
  31. public function setSoftCommit($soft_commit);
  32. /**
  33. * Tells whether this connection will use soft commits when comitting.
  34. *
  35. * Note that this setting only has any effect when using Solr 4.x or higher.
  36. *
  37. * @return
  38. * TRUE if soft commits will be used, FALSE otherwise.
  39. */
  40. public function getSoftCommit();
  41. /**
  42. * Set the stream context to use for requests to the Solr server.
  43. *
  44. * Must be a valid stream context as created by stream_context_create(). By
  45. * default, no special stream context will be used.
  46. *
  47. * @param resource|null $stream_context
  48. * A valid stream context as created by stream_context_create(). Or NULL to
  49. * use the default behavior.
  50. */
  51. public function setStreamContext($stream_context);
  52. /**
  53. * Returns the stream context to use for requests to the Solr server.
  54. *
  55. * By default, no special stream context will be used and this method will
  56. * return NULL.
  57. *
  58. * @return resource|null
  59. * A valid stream context as created by stream_context_create(). Or NULL if
  60. * the default behavior is used.
  61. */
  62. public function getStreamContext();
  63. /**
  64. * Gets information about the Solr Core.
  65. *
  66. * @return object
  67. * A response object with system information.
  68. */
  69. public function getSystemInfo();
  70. /**
  71. * Get metadata about fields in the Solr/Lucene index.
  72. *
  73. * @param int $num_terms
  74. * Number of 'top terms' to return.
  75. *
  76. * @return array
  77. * An array of SearchApiSolrField objects.
  78. */
  79. public function getFields($num_terms = 0);
  80. /**
  81. * Gets meta-data about the index.
  82. *
  83. * @param int $num_terms
  84. * Number of 'top terms' to return.
  85. *
  86. * @return object
  87. * A response object filled with data from Solr's Luke.
  88. */
  89. public function getLuke($num_terms = 0);
  90. /**
  91. * Gets information about the Solr core.
  92. *
  93. * @return SimpleXMLElement
  94. * A Simple XMl document.
  95. */
  96. public function getStats();
  97. /**
  98. * Gets summary information about the Solr Core.
  99. */
  100. public function getStatsSummary();
  101. /**
  102. * Clears the cached Solr data.
  103. */
  104. public function clearCache();
  105. /**
  106. * Makes a request to a servlet (a path) that's not a standard path.
  107. *
  108. * @param string $servlet
  109. * A path to be added to the base Solr path. e.g. 'extract/tika'.
  110. * @param array $params
  111. * Any request parameters when constructing the URL.
  112. * @param array $options
  113. * Options to be passed to drupal_http_request().
  114. *
  115. * @return object
  116. * The HTTP response object.
  117. *
  118. * @throws SearchApiException
  119. */
  120. public function makeServletRequest($servlet, array $params = array(), array $options = array());
  121. /**
  122. * Gets the base URL of the Solr server.
  123. *
  124. * @return string
  125. * The base URL of the Solr server.
  126. */
  127. public function getBaseUrl();
  128. /**
  129. * Sets the base URL of the Solr server.
  130. *
  131. * @param string $url
  132. * The new base URL of the Solr server.
  133. */
  134. public function setBaseUrl($url);
  135. /**
  136. * Sends a raw update request to the Solr server.
  137. *
  138. * Takes a raw post body and sends it to the update service. Post body should
  139. * be a complete and well-formed XML document.
  140. *
  141. * @param string $rawPost
  142. * The XML document to send to the Solr server's update service.
  143. * @param int|false $timeout
  144. * (optional) Maximum expected duration (in seconds).
  145. *
  146. * @return object
  147. * A response object.
  148. *
  149. * @throws SearchApiException
  150. * If an error occurs during the service call
  151. */
  152. public function update($rawPost, $timeout = 3600);
  153. /**
  154. * Adds an array of Solr Documents to the index all at once
  155. *
  156. * @param array $documents
  157. * Should be an array of ApacheSolrDocument instances
  158. * @param bool $overwrite
  159. * (optional) Set whether existing documents with the same IDs should be
  160. * overwritten. Defaults to TRUE.
  161. * @param bool $commitWithin
  162. * (optional) The time in which the indexed documents should be committed to
  163. * the index, in milliseconds. This works in addition to the Solr server's
  164. * auto commit settings. Defaults to no additional handling.
  165. *
  166. * @return object
  167. * A response object.
  168. *
  169. * @throws SearchApiException
  170. * If an error occurs during the service call.
  171. */
  172. public function addDocuments(array $documents, $overwrite = NULL, $commitWithin = NULL);
  173. /**
  174. * Sends a commit command to the Solr server.
  175. *
  176. * Will be synchronous unless $waitSearcher is set to FALSE.
  177. *
  178. * @param bool $waitSearcher
  179. * (optional) Wait until a new searcher is opened and registered as the main
  180. * query searcher, making the changes visible. Defaults to true.
  181. * @param int|false $timeout
  182. * Seconds to wait until timing out with an exception. Defaults to an hour.
  183. *
  184. * @return object
  185. * A response object.
  186. *
  187. * @throws SearchApiException
  188. * If an error occurs during the service call.
  189. */
  190. public function commit($waitSearcher = TRUE, $timeout = 3600);
  191. /**
  192. * Sends a delete request based on a document ID.
  193. *
  194. * @param string $id
  195. * The ID of the document which should be deleted. Expected to be UTF-8
  196. * encoded.
  197. * @param int|false $timeout
  198. * Seconds to wait until timing out with an exception. Defaults to an hour.
  199. *
  200. * @return object
  201. * A response object.
  202. *
  203. * @throws SearchApiException
  204. * If an error occurs during the service call.
  205. */
  206. public function deleteById($id, $timeout = 3600);
  207. /**
  208. * Sends a delete request for several documents, based on the document IDs.
  209. *
  210. * @param array $ids
  211. * The IDs of the documents which should be deleted. Expected to be UTF-8
  212. * encoded.
  213. * @param int|false $timeout
  214. * Seconds to wait until timing out with an exception. Defaults to an hour.
  215. *
  216. * @return object
  217. * A response object.
  218. *
  219. * @throws SearchApiException
  220. * If an error occurs during the service call.
  221. */
  222. public function deleteByMultipleIds(array $ids, $timeout = 3600);
  223. /**
  224. * Sends a delete request for all documents that match the given Solr query.
  225. *
  226. * @param string $rawQuery
  227. * The query whose results should be deleted. Expected to be UTF-8 encoded.
  228. * @param int|false $timeout
  229. * Seconds to wait until timing out with an exception. Defaults to an hour.
  230. *
  231. * @return object
  232. * A response object.
  233. *
  234. * @throws SearchApiException
  235. * If an error occurs during the service call.
  236. */
  237. public function deleteByQuery($rawQuery, $timeout = 3600);
  238. /**
  239. * Sends an optimize command to the Solr server.
  240. *
  241. * Will be synchronous unless $waitSearcher is set to FALSE.
  242. *
  243. * @param bool $waitSearcher
  244. * (optional) Wait until a new searcher is opened and registered as the main
  245. * query searcher, making the changes visible. Defaults to true.
  246. * @param int|false $timeout
  247. * Seconds to wait until timing out with an exception. Defaults to an hour.
  248. *
  249. * @return object
  250. * A response object.
  251. *
  252. * @throws SearchApiException
  253. * If an error occurs during the service call.
  254. */
  255. public function optimize($waitSearcher = TRUE, $timeout = 3600);
  256. /**
  257. * Executes a search on the Solr server.
  258. *
  259. * @param string|null $query
  260. * (optional) The raw query string. Defaults to an empty query.
  261. * @param array $params
  262. * (optional) Key / value pairs for other query parameters (see Solr
  263. * documentation). Use arrays for parameter keys used more than once (e.g.,
  264. * facet.field).
  265. * @param string $method
  266. * The HTTP method to use. Must be either "GET", "POST" or "AUTO". Defaults
  267. * to "GET".
  268. *
  269. * @return object
  270. * A response object.
  271. *
  272. * @throws SearchApiException
  273. * If an error occurs during the service call.
  274. */
  275. public function search($query = NULL, array $params = array(), $method = 'GET');
  276. /**
  277. * Escapes special characters from a Solr query.
  278. *
  279. * A complete list of special characters in Solr queries can be viewed at
  280. * http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
  281. *
  282. * @param string $value
  283. * The string to escape.
  284. * @param int $version
  285. * An integer representing the major solr version.
  286. *
  287. * @return string
  288. * An escaped string suitable for passing to Solr.
  289. */
  290. public static function escape($value, $version = 0);
  291. /**
  292. * Escapes a string that should be included in a Solr phrase.
  293. *
  294. * In contrast to escape(), this only escapes '"' and '\'.
  295. *
  296. * @param string $value
  297. * The string to escape.
  298. *
  299. * @return string
  300. * An escaped string suitable for passing to Solr.
  301. */
  302. public static function escapePhrase($value);
  303. /**
  304. * Converts a string to a Solr phrase.
  305. *
  306. * @param string $value
  307. * The string to convert to a phrase.
  308. *
  309. * @return string
  310. * A phrase string suitable for passing to Solr.
  311. */
  312. public static function phrase($value);
  313. /**
  314. * Escapes a Search API field name for passing to Solr.
  315. *
  316. * Since field names can only contain one special character, ":", there is no
  317. * need to use the complete escape() method.
  318. *
  319. * @param string $value
  320. * The field name to escape.
  321. *
  322. * @return string
  323. * An escaped string suitable for passing to Solr.
  324. */
  325. public static function escapeFieldName($value);
  326. /**
  327. * Gets the current solr version.
  328. *
  329. * @return int
  330. * 1, 3 or 4. Does not give a more detailed version, for that you need to
  331. * use getSystemInfo().
  332. */
  333. public function getSolrVersion();
  334. }