Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| LocalFeature | |
100.00% |
6 / 6 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| getKeywords | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| queryHeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCrossSearchStrategy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| doApply | |
100.00% |
2 / 2 |
|
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\Search\SearchContext; |
| 8 | |
| 9 | /** |
| 10 | * Limits the search to the local wiki. Primarily this excludes results from |
| 11 | * commons when searching the NS_FILE namespace. No value may be provided |
| 12 | * along with this keyword, it is a simple boolean flag. |
| 13 | */ |
| 14 | class LocalFeature extends SimpleKeywordFeature implements LegacyKeywordFeature { |
| 15 | |
| 16 | /** |
| 17 | * @return string[] The list of keywords this feature is supposed to match |
| 18 | */ |
| 19 | protected function getKeywords() { |
| 20 | return [ 'local' ]; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @return bool |
| 25 | */ |
| 26 | public function hasValue() { |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return bool |
| 32 | */ |
| 33 | public function queryHeader() { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @param KeywordFeatureNode $node |
| 39 | * @return CrossSearchStrategy |
| 40 | */ |
| 41 | public function getCrossSearchStrategy( KeywordFeatureNode $node ) { |
| 42 | return CrossSearchStrategy::hostWikiOnlyStrategy(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Applies the detected keyword from the search term. May apply changes |
| 47 | * either to $context directly, or return a filter to be added. |
| 48 | * |
| 49 | * @param SearchContext $context |
| 50 | * @param string $key The keyword |
| 51 | * @param string $value The value attached to the keyword with quotes stripped and escaped |
| 52 | * quotes un-escaped. |
| 53 | * @param string $quotedValue The original value in the search string, including quotes if used |
| 54 | * @param bool $negated Is the search negated? Not used to generate the returned AbstractQuery, |
| 55 | * that will be negated as necessary. Used for any other building/context necessary. |
| 56 | * @return array Two element array, first an AbstractQuery or null to apply to the |
| 57 | * query. Second a boolean indicating if the quotedValue should be kept in the search |
| 58 | * string. |
| 59 | */ |
| 60 | protected function doApply( SearchContext $context, $key, $value, $quotedValue, $negated ) { |
| 61 | $context->setLimitSearchToLocalWiki( true ); |
| 62 | return [ null, false ]; |
| 63 | } |
| 64 | } |