Dummy_Solr.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. /**
  3. * @file
  4. * Dummy object to simulate a Solr Service
  5. *
  6. */
  7. class DummySolr implements DrupalApacheSolrServiceInterface {
  8. function getId() {
  9. return __CLASS__;
  10. }
  11. function getFields($num_terms = 0) {
  12. return (object) array(
  13. 'is_uid' =>
  14. (object) array(
  15. 'type' => 'long',
  16. 'schema' => 'I-S----OF-----',
  17. ),
  18. 'content' =>
  19. (object) array(
  20. 'type' => 'text',
  21. 'schema' => 'ITS-V---------',
  22. ),
  23. 'im_3_field_tags' =>
  24. (object) array(
  25. 'type' => 'long',
  26. 'schema' => 'I-SM---OF-----',
  27. 'dynamicBase' => 'im_*',
  28. ),
  29. 'entity_type' =>
  30. (object) array(
  31. 'type' => 'string',
  32. 'schema' => 'I-S----OF----l',
  33. ),
  34. 'ds_last_comment_or_change' =>
  35. (object) array(
  36. 'type' => 'tdate',
  37. 'schema' => 'ITS----OF-----',
  38. ),
  39. 'nodeaccess_ari4jj_node_access_example_view' =>
  40. (object) array(
  41. 'type' => 'integer',
  42. 'schema' => 'I--M---OF-----',
  43. 'dynamicBase' => 'nodeaccess*',
  44. ),
  45. 'entity_id' =>
  46. (object) array(
  47. 'type' => 'tlong',
  48. 'schema' => 'ITS----OF-----',
  49. ),
  50. 'ds_changed' =>
  51. (object) array(
  52. 'type' => 'tdate',
  53. 'schema' => 'ITS----OF-----',
  54. ),
  55. 'id' =>
  56. (object) array(
  57. 'type' => 'string',
  58. 'schema' => 'I-S----OF----l',
  59. ),
  60. 'timestamp' =>
  61. (object) array(
  62. 'type' => 'date',
  63. 'schema' => 'I-S----OF----l',
  64. ),
  65. 'label' =>
  66. (object) array(
  67. 'type' => 'text',
  68. 'schema' => 'ITS-V--O------',
  69. ),
  70. 'nodeaccess_ari4jj_node_access_example_edit' =>
  71. (object) array(
  72. 'type' => 'integer',
  73. 'schema' => 'I--M---OF-----',
  74. 'dynamicBase' => 'nodeaccess*',
  75. ),
  76. 'ds_created' =>
  77. (object) array(
  78. 'type' => 'tdate',
  79. 'schema' => 'ITS----OF-----',
  80. ),
  81. 'ss_name' =>
  82. (object) array(
  83. 'type' => 'text',
  84. 'schema' => 'ITS-V---------',
  85. ),
  86. 'path' =>
  87. (object) array(
  88. 'type' => 'string',
  89. 'schema' => 'I-S----OF----l',
  90. ),
  91. 'taxonomy_names' =>
  92. (object) array(
  93. 'type' => 'text',
  94. 'schema' => 'IT-MV--O------',
  95. ),
  96. 'bundle' =>
  97. (object) array(
  98. 'type' => 'string',
  99. 'schema' => 'I-S----OF----l',
  100. ),
  101. 'tid' =>
  102. (object) array(
  103. 'type' => 'long',
  104. 'schema' => 'I-SM---OF-----',
  105. ),
  106. 'is_tnid' =>
  107. (object) array(
  108. 'type' => 'long',
  109. 'schema' => 'I-S----OF-----',
  110. ),
  111. 'nodeaccess_ari4jj_node_access_example_author' =>
  112. (object) array(
  113. 'type' => 'integer',
  114. 'schema' => 'I--M---OF-----',
  115. 'dynamicBase' => 'nodeaccess*',
  116. ),
  117. 'tm_vid_1_names' =>
  118. (object) array(
  119. 'type' => 'text',
  120. 'schema' => 'ITSMV---------',
  121. 'dynamicBase' => 'tm_*',
  122. ),
  123. 'spell' =>
  124. (object) array(
  125. 'type' => 'textSpell',
  126. 'schema' => 'ITSM----------',
  127. ),
  128. 'site' =>
  129. (object) array(
  130. 'type' => 'string',
  131. 'schema' => 'I-S----OF----l',
  132. ),
  133. 'is_comment_count' =>
  134. (object) array(
  135. 'type' => 'tint',
  136. 'schema' => 'ITS----OF-----',
  137. ),
  138. 'bundle_name' =>
  139. (object) array(
  140. 'type' => 'string',
  141. 'schema' => 'I-S----OF----l',
  142. ),
  143. 'hash' =>
  144. (object) array(
  145. 'type' => 'string',
  146. 'schema' => 'I-S----OF----l',
  147. ),
  148. 'bs_status' =>
  149. (object) array(
  150. 'type' => 'boolean',
  151. 'schema' => 'I-S----OF----l',
  152. ),
  153. 'entity_id' =>
  154. (object) array(
  155. 'type' => 'long',
  156. 'schema' => 'I-S----OF-----',
  157. ),
  158. 'url' =>
  159. (object) array(
  160. 'type' => 'string',
  161. 'schema' => 'I-S----OF----l',
  162. ),
  163. 'nodeaccess_all' =>
  164. (object) array(
  165. 'type' => 'integer',
  166. 'schema' => 'I--M---OF-----',
  167. 'dynamicBase' => 'nodeaccess*',
  168. ),
  169. 'sort_name' =>
  170. (object) array(
  171. 'type' => 'sortString',
  172. 'schema' => 'IT-----O-----l',
  173. ),
  174. 'tags_a' =>
  175. (object) array(
  176. 'type' => 'text',
  177. 'schema' => 'IT-----O------',
  178. 'dynamicBase' => 'tags_*',
  179. ),
  180. 'bs_sticky' =>
  181. (object) array(
  182. 'type' => 'boolean',
  183. 'schema' => 'I-S----OF----l',
  184. ),
  185. 'bs_promote' =>
  186. (object) array(
  187. 'type' => 'boolean',
  188. 'schema' => 'I-S----OF----l',
  189. ),
  190. 'teaser' =>
  191. (object) array(
  192. 'type' => 'text',
  193. 'schema' => '-TS-----------',
  194. ),
  195. 'im_vid_1' =>
  196. (object) array(
  197. 'type' => 'long',
  198. 'schema' => 'I-SM---OF-----',
  199. 'dynamicBase' => 'im_*',
  200. ),
  201. 'bs_translate' =>
  202. (object) array(
  203. 'type' => 'boolean',
  204. 'schema' => 'I-S----OF----l',
  205. ),
  206. 'sort_label' =>
  207. (object) array(
  208. 'type' => 'sortString',
  209. 'schema' => 'IT-----O-----l',
  210. ),
  211. 'ss_language' =>
  212. (object) array(
  213. 'type' => 'string',
  214. 'schema' => 'I-S----OF----l',
  215. ),
  216. 'sm_vid_Tags' =>
  217. (object) array(
  218. 'type' => 'string',
  219. 'schema' => 'I-SM---OF----l',
  220. 'dynamicBase' => 'sm_*',
  221. ),
  222. );
  223. }
  224. protected $last_search = array();
  225. public function search($query = '', array $params = array(), $method = 'GET') {
  226. $this->last_search = array('query' => $query, 'params' => $params, 'method' => $method);
  227. $response = new stdClass();
  228. $response->response = new stdClass();
  229. $response->response->numFound = 0;
  230. $response->response->docs = array();
  231. return $response;
  232. }
  233. public function getLastSearch() {
  234. return $this->last_search;
  235. }
  236. /**
  237. * Call the /admin/ping servlet, to test the connection to the server.
  238. *
  239. * @param $timeout
  240. * maximum time to wait for ping in seconds, -1 for unlimited (default 2).
  241. * @return
  242. * (float) seconds taken to ping the server, FALSE if timeout occurs.
  243. */
  244. function ping($timeout = 2) {
  245. }
  246. /**
  247. * Get information about the Solr Core.
  248. *
  249. * @return
  250. * (string) system info encoded in json
  251. */
  252. function getSystemInfo() {
  253. }
  254. /**
  255. * Get meta-data about the index.
  256. */
  257. function getLuke($num_terms = 0) {
  258. }
  259. /**
  260. * Get information about the Solr Core.
  261. *
  262. * Returns a Simple XMl document
  263. */
  264. function getStats() {
  265. }
  266. /**
  267. * Get summary information about the Solr Core.
  268. */
  269. function getStatsSummary() {
  270. }
  271. /**
  272. * Clear cached Solr data.
  273. */
  274. function clearCache() {
  275. }
  276. /**
  277. * Constructor
  278. *
  279. * @param $url
  280. * The URL to the Solr server, possibly including a core name. E.g. http://localhost:8983/solr/
  281. * or https://search.example.com/solr/core99/
  282. * @param $env_id
  283. * The machine name of a corresponding saved configuration used for loading
  284. * data like which facets are enabled.
  285. */
  286. function __construct($url, $env_id = NULL) {
  287. }
  288. /**
  289. * Make a request to a servlet (a path) that's not a standard path.
  290. *
  291. * @param string $servlet
  292. * A path to be added to the base Solr path. e.g. 'extract/tika'
  293. *
  294. * @param array $params
  295. * Any request parameters when constructing the URL.
  296. *
  297. * @param array $options
  298. * @see drupal_http_request() $options.
  299. *
  300. * @return
  301. * response object
  302. *
  303. * @thows Exception
  304. */
  305. function makeServletRequest($servlet, $params = array(), $options = array()) {
  306. }
  307. /**
  308. * Get the Solr url
  309. *
  310. * @return string
  311. */
  312. function getUrl() {
  313. }
  314. /**
  315. * Set the Solr url.
  316. *
  317. * @param $url
  318. *
  319. * @return $this
  320. */
  321. function setUrl($url) {
  322. }
  323. /**
  324. * Raw update Method. Takes a raw post body and sends it to the update service. Post body
  325. * should be a complete and well formed xml document.
  326. *
  327. * @param string $rawPost
  328. * @param float $timeout Maximum expected duration (in seconds)
  329. *
  330. * @return response object
  331. *
  332. * @throws Exception If an error occurs during the service call
  333. */
  334. function update($rawPost, $timeout = FALSE) {
  335. }
  336. /**
  337. * Add an array of Solr Documents to the index all at once
  338. *
  339. * @param array $documents Should be an array of ApacheSolrDocument instances
  340. * @param boolean $allowDups
  341. * @param boolean $overwritePending
  342. * @param boolean $overwriteCommitted
  343. *
  344. * @return response objecte
  345. *
  346. * @throws Exception If an error occurs during the service call
  347. */
  348. function addDocuments($documents, $overwrite = NULL, $commitWithin = NULL) {
  349. }
  350. /**
  351. * Send a commit command. Will be synchronous unless both wait parameters are set to false.
  352. *
  353. * @param boolean $optimize Defaults to true
  354. * @param boolean $waitFlush Defaults to true
  355. * @param boolean $waitSearcher Defaults to true
  356. * @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
  357. * @param boolean $softCommit optimize by using a softCommit
  358. *
  359. * @return response object
  360. *
  361. * @throws Exception If an error occurs during the service call
  362. */
  363. function commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600, $softCommit = FALSE) {
  364. }
  365. /**
  366. * Create a delete document based on document ID
  367. *
  368. * @param string $id Expected to be utf-8 encoded
  369. * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  370. *
  371. * @return response object
  372. *
  373. * @throws Exception If an error occurs during the service call
  374. */
  375. function deleteById($id, $timeout = 3600) {
  376. }
  377. /**
  378. * Create and post a delete document based on multiple document IDs.
  379. *
  380. * @param array $ids Expected to be utf-8 encoded strings
  381. * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  382. *
  383. * @return response object
  384. *
  385. * @throws Exception If an error occurs during the service call
  386. */
  387. function deleteByMultipleIds($ids, $timeout = 3600) {
  388. }
  389. /**
  390. * Create a delete document based on a query and submit it
  391. *
  392. * @param string $rawQuery Expected to be utf-8 encoded
  393. * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  394. * @return stdClass response object
  395. *
  396. * @throws Exception If an error occurs during the service call
  397. */
  398. function deleteByQuery($rawQuery, $timeout = 3600) {
  399. }
  400. /**
  401. * Send an optimize command. Will be synchronous unless both wait parameters are set
  402. * to false.
  403. *
  404. * @param boolean $waitFlush
  405. * @param boolean $waitSearcher
  406. * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
  407. * @param boolean $softCommit optimize by using a softCommit
  408. *
  409. * @return response object
  410. *
  411. * @throws Exception If an error occurs during the service call
  412. */
  413. function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600, $softCommit = FALSE) {
  414. }
  415. /**
  416. * Get the current solr version. This could be 1, 3 or 4
  417. *
  418. * @return int
  419. * 1, 3 or 4. Does not give a more details version, for that you need
  420. * to get the system info.
  421. */
  422. function getSolrVersion() {
  423. }
  424. /**
  425. * Get query name.
  426. */
  427. function getName() {
  428. }
  429. /**
  430. * Get query searcher name (for facetapi, views, pages, etc).
  431. */
  432. function getSearcher() {
  433. }
  434. /**
  435. * Get context values.
  436. */
  437. function getContext() {
  438. }
  439. /**
  440. * Set context value.
  441. */
  442. function addContext(array $context) {
  443. }
  444. }