1 | <?php |
---|
2 | /** |
---|
3 | * Copyright 2011 Bas de Nooijer. |
---|
4 | * Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation. |
---|
5 | * All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions are met: |
---|
9 | * |
---|
10 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
11 | * this list of conditions and the following disclaimer. |
---|
12 | * |
---|
13 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
14 | * this listof conditions and the following disclaimer in the documentation |
---|
15 | * and/or other materials provided with the distribution. |
---|
16 | * |
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
27 | * POSSIBILITY OF SUCH DAMAGE. |
---|
28 | * |
---|
29 | * The views and conclusions contained in the software and documentation are |
---|
30 | * those of the authors and should not be interpreted as representing official |
---|
31 | * policies, either expressed or implied, of the copyright holder. |
---|
32 | * |
---|
33 | * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> |
---|
34 | * @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com> |
---|
35 | * @license http://github.com/basdenooijer/solarium/raw/master/COPYING |
---|
36 | * @link http://www.solarium-project.org/ |
---|
37 | * |
---|
38 | * @package Solarium |
---|
39 | * @subpackage Query |
---|
40 | */ |
---|
41 | |
---|
42 | /** |
---|
43 | * MoreLikeThis Query |
---|
44 | * |
---|
45 | * Can be used to select documents and/or facets from Solr. This querytype has |
---|
46 | * lots of options and there are many Solarium subclasses for it. |
---|
47 | * See the Solr documentation and the relevant Solarium classes for more info. |
---|
48 | * |
---|
49 | * @package Solarium |
---|
50 | * @subpackage Query |
---|
51 | */ |
---|
52 | class Solarium_Query_MoreLikeThis extends Solarium_Query_Select |
---|
53 | { |
---|
54 | |
---|
55 | /** |
---|
56 | * Get type for this query |
---|
57 | * |
---|
58 | * @return string |
---|
59 | */ |
---|
60 | public function getType() |
---|
61 | { |
---|
62 | return Solarium_Client::QUERYTYPE_MORELIKETHIS; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Default options |
---|
67 | * |
---|
68 | * @var array |
---|
69 | */ |
---|
70 | protected $_options = array( |
---|
71 | 'handler' => 'mlt', |
---|
72 | 'resultclass' => 'Solarium_Result_MoreLikeThis', |
---|
73 | 'documentclass' => 'Solarium_Document_ReadOnly', |
---|
74 | 'query' => '*:*', |
---|
75 | 'start' => 0, |
---|
76 | 'rows' => 10, |
---|
77 | 'fields' => '*,score', |
---|
78 | 'interestingTerms' => 'none', |
---|
79 | 'matchinclude' => false, |
---|
80 | 'stream' => false |
---|
81 | ); |
---|
82 | |
---|
83 | /** |
---|
84 | * Set query stream option |
---|
85 | * |
---|
86 | * Set to true to post query content instead of using the URL param |
---|
87 | * |
---|
88 | * @link http://wiki.apache.org/solr/ContentStream ContentStream |
---|
89 | * |
---|
90 | * @param boolean $stream |
---|
91 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
92 | */ |
---|
93 | public function setQueryStream($stream) |
---|
94 | { |
---|
95 | return $this->_setOption('stream', $stream); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Get stream option |
---|
100 | * |
---|
101 | * @return boolean |
---|
102 | */ |
---|
103 | public function getQueryStream() |
---|
104 | { |
---|
105 | return $this->getOption('stream'); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Set the interestingTerms parameter. Must be one of: none, list, details. |
---|
110 | * |
---|
111 | * @see http://wiki.apache.org/solr/MoreLikeThisHandler#Params |
---|
112 | * @param string $term |
---|
113 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
114 | */ |
---|
115 | public function setInterestingTerms($term) |
---|
116 | { |
---|
117 | return $this->_setOption('interestingTerms', $term); |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * Get the interestingTerm parameter. |
---|
122 | * |
---|
123 | * @return string |
---|
124 | */ |
---|
125 | public function getInterestingTerms() |
---|
126 | { |
---|
127 | return $this->getOption('interestingTerms'); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * Set the match.include parameter, which is either 'true' or 'false'. |
---|
132 | * |
---|
133 | * @see http://wiki.apache.org/solr/MoreLikeThisHandler#Params |
---|
134 | * |
---|
135 | * @param boolean $include |
---|
136 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
137 | */ |
---|
138 | public function setMatchInclude($include) |
---|
139 | { |
---|
140 | return $this->_setOption('matchinclude', $include); |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * Get the match.include parameter. |
---|
145 | * |
---|
146 | * @return string |
---|
147 | */ |
---|
148 | public function getMatchInclude() |
---|
149 | { |
---|
150 | return $this->getOption('matchinclude'); |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * Set MLT fields option |
---|
155 | * |
---|
156 | * The fields to use for similarity. NOTE: if possible, these should have a |
---|
157 | * stored TermVector |
---|
158 | * |
---|
159 | * Separate multiple fields with commas. |
---|
160 | * |
---|
161 | * @param string $fields |
---|
162 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
163 | */ |
---|
164 | public function setMltFields($fields) |
---|
165 | { |
---|
166 | return $this->_setOption('mltfields', $fields); |
---|
167 | } |
---|
168 | |
---|
169 | /** |
---|
170 | * Get MLT fields option |
---|
171 | * |
---|
172 | * @return string|null |
---|
173 | */ |
---|
174 | public function getMltFields() |
---|
175 | { |
---|
176 | return $this->getOption('mltfields'); |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * Set minimumtermfrequency option |
---|
181 | * |
---|
182 | * Minimum Term Frequency - the frequency below which terms will be ignored |
---|
183 | * in the source doc. |
---|
184 | * |
---|
185 | * @param int $minimum |
---|
186 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
187 | */ |
---|
188 | public function setMinimumTermFrequency($minimum) |
---|
189 | { |
---|
190 | return $this->_setOption('minimumtermfrequency', $minimum); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * Get minimumtermfrequency option |
---|
195 | * |
---|
196 | * @return integer|null |
---|
197 | */ |
---|
198 | public function getMinimumTermFrequency() |
---|
199 | { |
---|
200 | return $this->getOption('minimumtermfrequency'); |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * Set minimumdocumentfrequency option |
---|
205 | * |
---|
206 | * Minimum Document Frequency - the frequency at which words will be |
---|
207 | * ignored which do not occur in at least this many docs. |
---|
208 | * |
---|
209 | * @param int $minimum |
---|
210 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
211 | */ |
---|
212 | public function setMinimumDocumentFrequency($minimum) |
---|
213 | { |
---|
214 | return $this->_setOption('minimumdocumentfrequency', $minimum); |
---|
215 | } |
---|
216 | |
---|
217 | /** |
---|
218 | * Get minimumdocumentfrequency option |
---|
219 | * |
---|
220 | * @return integer|null |
---|
221 | */ |
---|
222 | public function getMinimumDocumentFrequency() |
---|
223 | { |
---|
224 | return $this->getOption('minimumdocumentfrequency'); |
---|
225 | } |
---|
226 | |
---|
227 | /** |
---|
228 | * Set minimumwordlength option |
---|
229 | * |
---|
230 | * Minimum word length below which words will be ignored. |
---|
231 | * |
---|
232 | * @param int $minimum |
---|
233 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
234 | */ |
---|
235 | public function setMinimumWordLength($minimum) |
---|
236 | { |
---|
237 | return $this->_setOption('minimumwordlength', $minimum); |
---|
238 | } |
---|
239 | |
---|
240 | /** |
---|
241 | * Get minimumwordlength option |
---|
242 | * |
---|
243 | * @return integer|null |
---|
244 | */ |
---|
245 | public function getMinimumWordLength() |
---|
246 | { |
---|
247 | return $this->getOption('minimumwordlength'); |
---|
248 | } |
---|
249 | |
---|
250 | /** |
---|
251 | * Set maximumwordlength option |
---|
252 | * |
---|
253 | * Maximum word length above which words will be ignored. |
---|
254 | * |
---|
255 | * @param int $maximum |
---|
256 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
257 | */ |
---|
258 | public function setMaximumWordLength($maximum) |
---|
259 | { |
---|
260 | return $this->_setOption('maximumwordlength', $maximum); |
---|
261 | } |
---|
262 | |
---|
263 | /** |
---|
264 | * Get maximumwordlength option |
---|
265 | * |
---|
266 | * @return integer|null |
---|
267 | */ |
---|
268 | public function getMaximumWordLength() |
---|
269 | { |
---|
270 | return $this->getOption('maximumwordlength'); |
---|
271 | } |
---|
272 | |
---|
273 | /** |
---|
274 | * Set maximumqueryterms option |
---|
275 | * |
---|
276 | * Maximum number of query terms that will be included in any generated |
---|
277 | * query. |
---|
278 | * |
---|
279 | * @param int $maximum |
---|
280 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
281 | */ |
---|
282 | public function setMaximumQueryTerms($maximum) |
---|
283 | { |
---|
284 | return $this->_setOption('maximumqueryterms', $maximum); |
---|
285 | } |
---|
286 | |
---|
287 | /** |
---|
288 | * Get maximumqueryterms option |
---|
289 | * |
---|
290 | * @return integer|null |
---|
291 | */ |
---|
292 | public function getMaximumQueryTerms() |
---|
293 | { |
---|
294 | return $this->getOption('maximumqueryterms'); |
---|
295 | } |
---|
296 | |
---|
297 | /** |
---|
298 | * Set maximumnumberoftokens option |
---|
299 | * |
---|
300 | * Maximum number of tokens to parse in each example doc field that is not |
---|
301 | * stored with TermVector support. |
---|
302 | * |
---|
303 | * @param int $maximum |
---|
304 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
305 | */ |
---|
306 | public function setMaximumNumberOfTokens($maximum) |
---|
307 | { |
---|
308 | return $this->_setOption('maximumnumberoftokens', $maximum); |
---|
309 | } |
---|
310 | |
---|
311 | /** |
---|
312 | * Get maximumnumberoftokens option |
---|
313 | * |
---|
314 | * @return integer|null |
---|
315 | */ |
---|
316 | public function getMaximumNumberOfTokens() |
---|
317 | { |
---|
318 | return $this->getOption('maximumnumberoftokens'); |
---|
319 | } |
---|
320 | |
---|
321 | /** |
---|
322 | * Set boost option |
---|
323 | * |
---|
324 | * If true the query will be boosted by the interesting term relevance. |
---|
325 | * |
---|
326 | * @param boolean $boost |
---|
327 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
328 | */ |
---|
329 | public function setBoost($boost) |
---|
330 | { |
---|
331 | return $this->_setOption('boost', $boost); |
---|
332 | } |
---|
333 | |
---|
334 | /** |
---|
335 | * Get boost option |
---|
336 | * |
---|
337 | * @return boolean|null |
---|
338 | */ |
---|
339 | public function getBoost() |
---|
340 | { |
---|
341 | return $this->getOption('boost'); |
---|
342 | } |
---|
343 | |
---|
344 | /** |
---|
345 | * Set queryfields option |
---|
346 | * |
---|
347 | * Query fields and their boosts using the same format as that used in |
---|
348 | * DisMaxQParserPlugin. These fields must also be specified in fields. |
---|
349 | * |
---|
350 | * Separate multiple fields with commas. |
---|
351 | * |
---|
352 | * @param string $queryFields |
---|
353 | * @return Solarium_Query_MoreLikeThis Provides fluent interface |
---|
354 | */ |
---|
355 | public function setQueryFields($queryFields) |
---|
356 | { |
---|
357 | return $this->_setOption('queryfields', $queryFields); |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * Get queryfields option |
---|
362 | * |
---|
363 | * @return string|null |
---|
364 | */ |
---|
365 | public function getQueryFields() |
---|
366 | { |
---|
367 | return $this->getOption('queryfields'); |
---|
368 | } |
---|
369 | |
---|
370 | } |
---|