Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TermFreq
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace CirrusSearch\Extra\Query;
4
5use Elastica\Query\AbstractQuery;
6use 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
31class TermFreq extends AbstractQuery {
32
33    private static $map = [
34        '>' => 'gt',
35        '>=' => 'gte',
36        '<' => 'lt',
37        '<=' => 'lte',
38        '=' => 'eq',
39    ];
40
41    /**
42     * @param string $field The name of the field to search
43     * @param string $term The term to search for
44     * @param string $operator A comparison operator. One of [ '<', '<=', '>', '>=', '=' ]
45     * @param int $number The number to compare against
46     */
47    public function __construct( $field, $term, $operator, $number ) {
48        Assert::parameter(
49            isset( self::$map[$operator] ),
50            $operator,
51            "operator must be one of " . implode( ', ', array_keys( self::$map ) )
52        );
53        if ( $field !== '' && $term !== '' ) {
54            $this->setParam( 'field', $field );
55            $this->setParam( 'term', $term );
56            $this->setParam( self::$map[ $operator ], $number );
57        }
58    }
59
60}