solr_connection.interface.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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). Defaults to not timing
  145. * out.
  146. *
  147. * @return object
  148. * A response object.
  149. *
  150. * @throws SearchApiException
  151. * If an error occurs during the service call
  152. */
  153. public function update($rawPost, $timeout = FALSE);
  154. /**
  155. * Adds an array of Solr Documents to the index all at once
  156. *
  157. * @param array $documents
  158. * Should be an array of ApacheSolrDocument instances
  159. * @param bool $overwrite
  160. * (optional) Set whether existing documents with the same IDs should be
  161. * overwritten. Defaults to TRUE.
  162. * @param bool $commitWithin
  163. * (optional) The time in which the indexed documents should be committed to
  164. * the index, in milliseconds. This works in addition to the Solr server's
  165. * auto commit settings. Defaults to no additional handling.
  166. *
  167. * @return object
  168. * A response object.
  169. *
  170. * @throws SearchApiException
  171. * If an error occurs during the service call.
  172. */
  173. public function addDocuments(array $documents, $overwrite = NULL, $commitWithin = NULL);
  174. /**
  175. * Sends a commit command to the Solr server.
  176. *
  177. * Will be synchronous unless $waitSearcher is set to FALSE.
  178. *
  179. * @param bool $waitSearcher
  180. * (optional) Wait until a new searcher is opened and registered as the main
  181. * query searcher, making the changes visible. Defaults to true.
  182. * @param int|false $timeout
  183. * Seconds to wait until timing out with an exception. Defaults to an hour.
  184. *
  185. * @return object
  186. * A response object.
  187. *
  188. * @throws SearchApiException
  189. * If an error occurs during the service call.
  190. */
  191. public function commit($waitSearcher = TRUE, $timeout = 3600);
  192. /**
  193. * Sends a delete request based on a document ID.
  194. *
  195. * @param string $id
  196. * The ID of the document which should be deleted. Expected to be UTF-8
  197. * encoded.
  198. * @param int|false $timeout
  199. * Seconds to wait until timing out with an exception. Defaults to an hour.
  200. *
  201. * @return object
  202. * A response object.
  203. *
  204. * @throws SearchApiException
  205. * If an error occurs during the service call.
  206. */
  207. public function deleteById($id, $timeout = 3600);
  208. /**
  209. * Sends a delete request for several documents, based on the document IDs.
  210. *
  211. * @param array $id
  212. * The IDs of the documents which should be deleted. Expected to be UTF-8
  213. * encoded.
  214. * @param int|false $timeout
  215. * Seconds to wait until timing out with an exception. Defaults to an hour.
  216. *
  217. * @return object
  218. * A response object.
  219. *
  220. * @throws SearchApiException
  221. * If an error occurs during the service call.
  222. */
  223. public function deleteByMultipleIds(array $ids, $timeout = 3600);
  224. /**
  225. * Sends a delete request for all documents that match the given Solr query.
  226. *
  227. * @param string $rawQuery
  228. * The query whose results should be deleted. Expected to be UTF-8 encoded.
  229. * @param int|false $timeout
  230. * Seconds to wait until timing out with an exception. Defaults to an hour.
  231. *
  232. * @return object
  233. * A response object.
  234. *
  235. * @throws SearchApiException
  236. * If an error occurs during the service call.
  237. */
  238. public function deleteByQuery($rawQuery, $timeout = 3600);
  239. /**
  240. * Sends an optimize command to the Solr server.
  241. *
  242. * Will be synchronous unless $waitSearcher is set to FALSE.
  243. *
  244. * @param bool $waitSearcher
  245. * (optional) Wait until a new searcher is opened and registered as the main
  246. * query searcher, making the changes visible. Defaults to true.
  247. * @param int|false $timeout
  248. * Seconds to wait until timing out with an exception. Defaults to an hour.
  249. *
  250. * @return object
  251. * A response object.
  252. *
  253. * @throws SearchApiException
  254. * If an error occurs during the service call.
  255. */
  256. public function optimize($waitSearcher = TRUE, $timeout = 3600);
  257. /**
  258. * Executes a search on the Solr server.
  259. *
  260. * @param string|null $query
  261. * (optional) The raw query string. Defaults to an empty query.
  262. * @param array $params
  263. * (optional) Key / value pairs for other query parameters (see Solr
  264. * documentation). Use arrays for parameter keys used more than once (e.g.,
  265. * facet.field).
  266. * @param string $method
  267. * The HTTP method to use. Must be either "GET", "POST" or "AUTO". Defaults
  268. * to "GET".
  269. *
  270. * @return object
  271. * A response object.
  272. *
  273. * @throws SearchApiException
  274. * If an error occurs during the service call.
  275. */
  276. public function search($query = NULL, array $params = array(), $method = 'GET');
  277. /**
  278. * Escapes special characters from a Solr query.
  279. *
  280. * A complete list of special characters in Solr queries can be viewed at
  281. * http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
  282. *
  283. * @param string $value
  284. * The string to escape.
  285. * @param string $version
  286. * An integer representing major solr version release.
  287. *
  288. * @return string
  289. * An escaped string suitable for passing to Solr.
  290. */
  291. public static function escape($value, $version = 0);
  292. /**
  293. * Escapes a string that should be included in a Solr phrase.
  294. *
  295. * In contrast to escape(), this only escapes '"' and '\'.
  296. *
  297. * @param string $value
  298. * The string to escape.
  299. *
  300. * @return string
  301. * An escaped string suitable for passing to Solr.
  302. */
  303. public static function escapePhrase($value);
  304. /**
  305. * Converts a string to a Solr phrase.
  306. *
  307. * @param string $value
  308. * The string to convert to a phrase.
  309. *
  310. * @return string
  311. * A phrase string suitable for passing to Solr.
  312. */
  313. public static function phrase($value);
  314. /**
  315. * Escapes a Search API field name for passing to Solr.
  316. *
  317. * Since field names can only contain one special character, ":", there is no
  318. * need to use the complete escape() method.
  319. *
  320. * @param string $value
  321. * The field name to escape.
  322. *
  323. * @return string
  324. * An escaped string suitable for passing to Solr.
  325. */
  326. public static function escapeFieldName($value);
  327. /**
  328. * Gets the current solr version.
  329. *
  330. * @return int
  331. * 1, 3 or 4. Does not give a more detailed version, for that you need to
  332. * use getSystemInfo().
  333. */
  334. public function getSolrVersion();
  335. }