PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/solarium/solarium/library/Solarium/QueryType/Select/Query/Component/Spellcheck.php

https://gitlab.com/Blueprint-Marketing/solr-power
PHP | 397 lines | 137 code | 36 blank | 224 comment | 1 complexity | 3a3fad947d9a59d048887d59a8efa287 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright 2011 Bas de Nooijer. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this listof conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * The views and conclusions contained in the software and documentation are
  28. * those of the authors and should not be interpreted as representing official
  29. * policies, either expressed or implied, of the copyright holder.
  30. *
  31. * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
  32. * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
  33. * @link http://www.solarium-project.org/
  34. */
  35. /**
  36. * @namespace
  37. */
  38. namespace Solarium\QueryType\Select\Query\Component;
  39. use Solarium\QueryType\Select\Query\Query as SelectQuery;
  40. use Solarium\QueryType\Select\RequestBuilder\Component\Spellcheck as RequestBuilder;
  41. use Solarium\QueryType\Select\ResponseParser\Component\Spellcheck as ResponseParser;
  42. /**
  43. * Spellcheck component
  44. *
  45. * @link http://wiki.apache.org/solr/SpellCheckComponent
  46. */
  47. class Spellcheck extends Component
  48. {
  49. /**
  50. * Used to further customize collation parameters
  51. * @var array
  52. */
  53. protected $collateParams = array();
  54. /**
  55. * Get component type
  56. *
  57. * @return string
  58. */
  59. public function getType()
  60. {
  61. return SelectQuery::COMPONENT_SPELLCHECK;
  62. }
  63. /**
  64. * Get a requestbuilder for this query
  65. *
  66. * @return RequestBuilder
  67. */
  68. public function getRequestBuilder()
  69. {
  70. return new RequestBuilder;
  71. }
  72. /**
  73. * Get a response parser for this query
  74. *
  75. * @return ResponseParser
  76. */
  77. public function getResponseParser()
  78. {
  79. return new ResponseParser;
  80. }
  81. /**
  82. * Set spellcheck query option
  83. *
  84. * @param string $query
  85. * @param array $bind Bind values for placeholders in the query string
  86. * @return self Provides fluent interface
  87. */
  88. public function setQuery($query, $bind = null)
  89. {
  90. if (!is_null($bind)) {
  91. $query = $this->getQueryInstance()->getHelper()->assemble($query, $bind);
  92. }
  93. return $this->setOption('query', trim($query));
  94. }
  95. /**
  96. * Get query option
  97. *
  98. * @return string|null
  99. */
  100. public function getQuery()
  101. {
  102. return $this->getOption('query');
  103. }
  104. /**
  105. * Set build option
  106. *
  107. * Build the spellcheck?
  108. *
  109. * @param boolean $build
  110. * @return self Provides fluent interface
  111. */
  112. public function setBuild($build)
  113. {
  114. return $this->setOption('build', $build);
  115. }
  116. /**
  117. * Get build option
  118. *
  119. * @return boolean|null
  120. */
  121. public function getBuild()
  122. {
  123. return $this->getOption('build');
  124. }
  125. /**
  126. * Set reload option
  127. *
  128. * Reload the dictionary?
  129. *
  130. * @param boolean $reload
  131. * @return self Provides fluent interface
  132. */
  133. public function setReload($reload)
  134. {
  135. return $this->setOption('reload', $reload);
  136. }
  137. /**
  138. * Get fragsize option
  139. *
  140. * @return boolean|null
  141. */
  142. public function getReload()
  143. {
  144. return $this->getOption('reload');
  145. }
  146. /**
  147. * Set dictionary option
  148. *
  149. * The name of the dictionary to use
  150. *
  151. * @param string $dictionary
  152. * @return self Provides fluent interface
  153. */
  154. public function setDictionary($dictionary)
  155. {
  156. return $this->setOption('dictionary', $dictionary);
  157. }
  158. /**
  159. * Get dictionary option
  160. *
  161. * @return string|null
  162. */
  163. public function getDictionary()
  164. {
  165. return $this->getOption('dictionary');
  166. }
  167. /**
  168. * Set count option
  169. *
  170. * The maximum number of suggestions to return
  171. *
  172. * @param int $count
  173. * @return self Provides fluent interface
  174. */
  175. public function setCount($count)
  176. {
  177. return $this->setOption('count', $count);
  178. }
  179. /**
  180. * Get count option
  181. *
  182. * @return int|null
  183. */
  184. public function getCount()
  185. {
  186. return $this->getOption('count');
  187. }
  188. /**
  189. * Set onlyMorePopular option
  190. *
  191. * Only return suggestions that result in more hits for the query than the existing query
  192. *
  193. * @param boolean $onlyMorePopular
  194. * @return self Provides fluent interface
  195. */
  196. public function setOnlyMorePopular($onlyMorePopular)
  197. {
  198. return $this->setOption('onlymorepopular', $onlyMorePopular);
  199. }
  200. /**
  201. * Get onlyMorePopular option
  202. *
  203. * @return boolean|null
  204. */
  205. public function getOnlyMorePopular()
  206. {
  207. return $this->getOption('onlymorepopular');
  208. }
  209. /**
  210. * Set extendedResults option
  211. *
  212. * @param boolean $extendedResults
  213. * @return self Provides fluent interface
  214. */
  215. public function setExtendedResults($extendedResults)
  216. {
  217. return $this->setOption('extendedresults', $extendedResults);
  218. }
  219. /**
  220. * Get extendedResults option
  221. *
  222. * @return boolean|null
  223. */
  224. public function getExtendedResults()
  225. {
  226. return $this->getOption('extendedresults');
  227. }
  228. /**
  229. * Set collate option
  230. *
  231. * @param boolean $collate
  232. * @return self Provides fluent interface
  233. */
  234. public function setCollate($collate)
  235. {
  236. return $this->setOption('collate', $collate);
  237. }
  238. /**
  239. * Get collate option
  240. *
  241. * @return boolean|null
  242. */
  243. public function getCollate()
  244. {
  245. return $this->getOption('collate');
  246. }
  247. /**
  248. * Set maxCollations option
  249. *
  250. * @param int $maxCollations
  251. * @return self Provides fluent interface
  252. */
  253. public function setMaxCollations($maxCollations)
  254. {
  255. return $this->setOption('maxcollations', $maxCollations);
  256. }
  257. /**
  258. * Get maxCollations option
  259. *
  260. * @return int|null
  261. */
  262. public function getMaxCollations()
  263. {
  264. return $this->getOption('maxcollations');
  265. }
  266. /**
  267. * Set maxCollationTries option
  268. *
  269. * @param string $maxCollationTries
  270. * @return self Provides fluent interface
  271. */
  272. public function setMaxCollationTries($maxCollationTries)
  273. {
  274. return $this->setOption('maxcollationtries', $maxCollationTries);
  275. }
  276. /**
  277. * Get maxCollationTries option
  278. *
  279. * @return string|null
  280. */
  281. public function getMaxCollationTries()
  282. {
  283. return $this->getOption('maxcollationtries');
  284. }
  285. /**
  286. * Set maxCollationEvaluations option
  287. *
  288. * @param int $maxCollationEvaluations
  289. * @return self Provides fluent interface
  290. */
  291. public function setMaxCollationEvaluations($maxCollationEvaluations)
  292. {
  293. return $this->setOption('maxcollationevaluations', $maxCollationEvaluations);
  294. }
  295. /**
  296. * Get maxCollationEvaluations option
  297. *
  298. * @return int|null
  299. */
  300. public function getMaxCollationEvaluations()
  301. {
  302. return $this->getOption('maxcollationevaluations');
  303. }
  304. /**
  305. * Set collateExtendedResults option
  306. *
  307. * @param string $collateExtendedResults
  308. * @return self Provides fluent interface
  309. */
  310. public function setCollateExtendedResults($collateExtendedResults)
  311. {
  312. return $this->setOption('collateextendedresults', $collateExtendedResults);
  313. }
  314. /**
  315. * Get collateExtendedResults option
  316. *
  317. * @return string|null
  318. */
  319. public function getCollateExtendedResults()
  320. {
  321. return $this->getOption('collateextendedresults');
  322. }
  323. /**
  324. * Set accuracy option
  325. *
  326. * @param float $accuracy
  327. * @return self Provides fluent interface
  328. */
  329. public function setAccuracy($accuracy)
  330. {
  331. return $this->setOption('accuracy', $accuracy);
  332. }
  333. /**
  334. * Get accuracy option
  335. *
  336. * @return float|null
  337. */
  338. public function getAccuracy()
  339. {
  340. return $this->getOption('accuracy');
  341. }
  342. /**
  343. * Set a collation param
  344. * @param string $param
  345. * @param mixed $value
  346. * @return self Provides fluent interface
  347. */
  348. public function setCollateParam($param, $value)
  349. {
  350. $this->collateParams[$param] = $value;
  351. return $this;
  352. }
  353. /**
  354. * Returns the array of collate params
  355. * @return array
  356. */
  357. public function getCollateParams()
  358. {
  359. return $this->collateParams;
  360. }
  361. }