Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
TermFreq | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Extra\Query; |
4 | |
5 | use Elastica\Query\AbstractQuery; |
6 | use Wikimedia\Assert\Assert; |
7 | |
8 | /** |
9 | * Filtering based on integer comparisons on the frequency of a term |
10 | * |
11 | * @link https://github.com/wikimedia/search-extra/blob/master/docs/term_freq_token_filter.md |
12 | * |
13 | * NOTE: only available if CirrusSearchWikimediaExtraPlugin['term_freq'] is set to true. |
14 | * |
15 | * This program is free software; you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation; either version 2 of the License, or |
18 | * (at your option) any later version. |
19 | * |
20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. |
24 | * |
25 | * You should have received a copy of the GNU General Public License along |
26 | * with this program; if not, write to the Free Software Foundation, Inc., |
27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
28 | * http://www.gnu.org/copyleft/gpl.html |
29 | */ |
30 | |
31 | class TermFreq extends AbstractQuery { |
32 | |
33 | /** @var string[] */ |
34 | private static $map = [ |
35 | '>' => 'gt', |
36 | '>=' => 'gte', |
37 | '<' => 'lt', |
38 | '<=' => 'lte', |
39 | '=' => 'eq', |
40 | ]; |
41 | |
42 | /** |
43 | * @param string $field The name of the field to search |
44 | * @param string $term The term to search for |
45 | * @param string $operator A comparison operator. One of [ '<', '<=', '>', '>=', '=' ] |
46 | * @param int $number The number to compare against |
47 | */ |
48 | public function __construct( $field, $term, $operator, $number ) { |
49 | Assert::parameter( |
50 | isset( self::$map[$operator] ), |
51 | $operator, |
52 | "operator must be one of " . implode( ', ', array_keys( self::$map ) ) |
53 | ); |
54 | if ( $field !== '' && $term !== '' ) { |
55 | $this->setParam( 'field', $field ); |
56 | $this->setParam( 'term', $term ); |
57 | $this->setParam( self::$map[ $operator ], $number ); |
58 | } |
59 | } |
60 | |
61 | } |