Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
ContentModelFeature | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
getKeywords | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCrossSearchStrategy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doApply | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFilterQuery | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doGetFilterQuery | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Query; |
4 | |
5 | use CirrusSearch\CrossSearchStrategy; |
6 | use CirrusSearch\Parser\AST\KeywordFeatureNode; |
7 | use CirrusSearch\Query\Builder\QueryBuildingContext; |
8 | use CirrusSearch\Search\SearchContext; |
9 | use Elastica\Query; |
10 | use Elastica\Query\AbstractQuery; |
11 | |
12 | /** |
13 | * Content model feature: |
14 | * contentmodel:wikitext |
15 | * Selects only articles having this content model. |
16 | */ |
17 | class ContentModelFeature extends SimpleKeywordFeature implements FilterQueryFeature { |
18 | /** |
19 | * @return string[] |
20 | */ |
21 | protected function getKeywords() { |
22 | return [ 'contentmodel' ]; |
23 | } |
24 | |
25 | /** |
26 | * @param KeywordFeatureNode $node |
27 | * @return CrossSearchStrategy |
28 | */ |
29 | public function getCrossSearchStrategy( KeywordFeatureNode $node ) { |
30 | return CrossSearchStrategy::allWikisStrategy(); |
31 | } |
32 | |
33 | /** |
34 | * @param SearchContext $context |
35 | * @param string $key The keyword |
36 | * @param string $value The value attached to the keyword with quotes stripped |
37 | * @param string $quotedValue The original value in the search string, including quotes |
38 | * if used |
39 | * @param bool $negated Is the search negated? Not used to generate the returned |
40 | * AbstractQuery, that will be negated as necessary. Used for any other building/context |
41 | * necessary. |
42 | * @return array Two element array, first an AbstractQuery or null to apply to the |
43 | * query. Second a boolean indicating if the quotedValue should be kept in the search |
44 | * string. |
45 | */ |
46 | protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) { |
47 | return [ $this->doGetFilterQuery( $value ), false ]; |
48 | } |
49 | |
50 | /** |
51 | * @param KeywordFeatureNode $node |
52 | * @param QueryBuildingContext $context |
53 | * @return AbstractQuery|null |
54 | */ |
55 | public function getFilterQuery( KeywordFeatureNode $node, QueryBuildingContext $context ) { |
56 | return $this->doGetFilterQuery( $node->getValue() ); |
57 | } |
58 | |
59 | /** |
60 | * @param string $value |
61 | * @return Query\MatchQuery |
62 | */ |
63 | private function doGetFilterQuery( $value ) { |
64 | return new Query\MatchQuery( 'content_model', [ 'query' => $value ] ); |
65 | } |
66 | } |