Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
LinksToFeature | |
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\AbstractQuery; |
10 | |
11 | /** |
12 | * Filters the result set based on pages containing outgoing wiki links to the |
13 | * provided page title. |
14 | * |
15 | * Examples: |
16 | * linksto:"Wake Island" |
17 | * linksto:Wake_Island |
18 | * linksto:Shanghai |
19 | */ |
20 | class LinksToFeature extends SimpleKeywordFeature implements FilterQueryFeature { |
21 | /** |
22 | * @return string[] |
23 | */ |
24 | protected function getKeywords() { |
25 | return [ 'linksto' ]; |
26 | } |
27 | |
28 | /** |
29 | * @param KeywordFeatureNode $node |
30 | * @return CrossSearchStrategy |
31 | */ |
32 | public function getCrossSearchStrategy( KeywordFeatureNode $node ) { |
33 | return CrossSearchStrategy::allWikisStrategy(); |
34 | } |
35 | |
36 | /** |
37 | * @param SearchContext $context |
38 | * @param string $key The keyword |
39 | * @param string $value The value attached to the keyword with quotes stripped |
40 | * @param string $quotedValue The original value in the search string, including quotes if used |
41 | * @param bool $negated Is the search negated? Not used to generate the returned AbstractQuery, |
42 | * that will be negated as necessary. Used for any other building/context necessary. |
43 | * @return array Two element array, first an AbstractQuery or null to apply to the |
44 | * query. Second a boolean indicating if the quotedValue should be kept in the search |
45 | * string. |
46 | */ |
47 | protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) { |
48 | return [ $this->doGetFilterQuery( $value ), false ]; |
49 | } |
50 | |
51 | /** |
52 | * @param KeywordFeatureNode $node |
53 | * @param QueryBuildingContext $context |
54 | * @return AbstractQuery|null |
55 | */ |
56 | public function getFilterQuery( KeywordFeatureNode $node, QueryBuildingContext $context ) { |
57 | return $this->doGetFilterQuery( $node->getValue() ); |
58 | } |
59 | |
60 | /** |
61 | * @param string $value |
62 | * @return \Elastica\Query\MatchQuery |
63 | */ |
64 | protected function doGetFilterQuery( $value ) { |
65 | return QueryHelper::matchPage( 'outgoing_link', $value, true ); |
66 | } |
67 | |
68 | } |