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 | * @license GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | namespace CirrusSearch\Extra\Query; |
| 7 | |
| 8 | use Elastica\Query\AbstractQuery; |
| 9 | use Wikimedia\Assert\Assert; |
| 10 | |
| 11 | /** |
| 12 | * Filtering based on integer comparisons on the frequency of a term |
| 13 | * |
| 14 | * @link https://github.com/wikimedia/search-extra/blob/master/docs/term_freq_token_filter.md |
| 15 | * |
| 16 | * NOTE: only available if CirrusSearchWikimediaExtraPlugin['term_freq'] is set to true. |
| 17 | */ |
| 18 | class TermFreq extends AbstractQuery { |
| 19 | |
| 20 | /** @var string[] */ |
| 21 | private static $map = [ |
| 22 | '>' => 'gt', |
| 23 | '>=' => 'gte', |
| 24 | '<' => 'lt', |
| 25 | '<=' => 'lte', |
| 26 | '=' => 'eq', |
| 27 | ]; |
| 28 | |
| 29 | /** |
| 30 | * @param string $field The name of the field to search |
| 31 | * @param string $term The term to search for |
| 32 | * @param string $operator A comparison operator. One of [ '<', '<=', '>', '>=', '=' ] |
| 33 | * @param int $number The number to compare against |
| 34 | */ |
| 35 | public function __construct( $field, $term, $operator, $number ) { |
| 36 | Assert::parameter( |
| 37 | isset( self::$map[$operator] ), |
| 38 | $operator, |
| 39 | "operator must be one of " . implode( ', ', array_keys( self::$map ) ) |
| 40 | ); |
| 41 | if ( $field !== '' && $term !== '' ) { |
| 42 | $this->setParam( 'field', $field ); |
| 43 | $this->setParam( 'term', $term ); |
| 44 | $this->setParam( self::$map[ $operator ], $number ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | } |