Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| CrossSearchStrategy | |
100.00% |
20 / 20 |
|
100.00% |
7 / 7 |
15 | |
100.00% |
1 / 1 |
| hostWikiOnlyStrategy | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| allWikisStrategy | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| isCrossProjectSearchSupported | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isCrossLanguageSearchSupported | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isExtraIndicesSearchSupported | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| intersect | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
9 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch; |
| 4 | |
| 5 | /** |
| 6 | * Defines support strategies regarding cross wiki searches. |
| 7 | * |
| 8 | * Cross wiki search techniques include: |
| 9 | * - extra indices searches (i.e. search media files on commons) |
| 10 | * - cross project searches |
| 11 | * - cross language searches (i.e. second try attempt) |
| 12 | */ |
| 13 | class CrossSearchStrategy { |
| 14 | /** |
| 15 | * @see InterwikiSearcher |
| 16 | * @var bool |
| 17 | */ |
| 18 | private $crossProjectSearchSupported; |
| 19 | |
| 20 | /** |
| 21 | * @see \CirrusSearch::searchTextSecondTry() |
| 22 | * @var bool |
| 23 | */ |
| 24 | private $crossLanguageSearchSupported; |
| 25 | |
| 26 | /** |
| 27 | * Controlled by $wgCirrusSearchExtraIndexes |
| 28 | * (Usually used to search media files on commons from any host wikis) |
| 29 | * @var bool |
| 30 | */ |
| 31 | private $extraIndicesSearchSupported; |
| 32 | |
| 33 | /** |
| 34 | * @var self |
| 35 | */ |
| 36 | private static $hostWikiOnly; |
| 37 | |
| 38 | /** |
| 39 | * @var self |
| 40 | */ |
| 41 | private static $allWikisStrategy; |
| 42 | |
| 43 | /** |
| 44 | * Only host wiki is supported |
| 45 | * Applies to features that are probably not available on any |
| 46 | * other target wiki cirrus may access. |
| 47 | */ |
| 48 | public static function hostWikiOnlyStrategy(): self { |
| 49 | self::$hostWikiOnly ??= new self( false, false, false ); |
| 50 | return self::$hostWikiOnly; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Applies to features that must be available on any target wiki. |
| 55 | */ |
| 56 | public static function allWikisStrategy(): self { |
| 57 | self::$allWikisStrategy ??= new self( true, true, true ); |
| 58 | return self::$allWikisStrategy; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param bool $crossProjectSearchSupported |
| 63 | * @param bool $crossLanguageSearchSupported |
| 64 | * @param bool $extraIndicesSupported |
| 65 | */ |
| 66 | public function __construct( $crossProjectSearchSupported, $crossLanguageSearchSupported, $extraIndicesSupported ) { |
| 67 | $this->crossProjectSearchSupported = $crossProjectSearchSupported; |
| 68 | $this->crossLanguageSearchSupported = $crossLanguageSearchSupported; |
| 69 | $this->extraIndicesSearchSupported = $extraIndicesSupported; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Is cross project search supported (aka interwiki search) |
| 74 | * @return bool |
| 75 | */ |
| 76 | public function isCrossProjectSearchSupported() { |
| 77 | return $this->crossProjectSearchSupported; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Is cross language search supported (i.e. second try language search) |
| 82 | * @return bool |
| 83 | */ |
| 84 | public function isCrossLanguageSearchSupported() { |
| 85 | return $this->crossLanguageSearchSupported; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * (in WMF context it's most commonly used to search media files |
| 90 | * on commons from any wikis.) |
| 91 | * |
| 92 | * See wgCirrusSearchExtraIndexes |
| 93 | * @return bool |
| 94 | */ |
| 95 | public function isExtraIndicesSearchSupported() { |
| 96 | return $this->extraIndicesSearchSupported; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Intersect this strategy with other. |
| 101 | */ |
| 102 | public function intersect( self $other ): self { |
| 103 | if ( $other === self::hostWikiOnlyStrategy() || $this === self::hostWikiOnlyStrategy() ) { |
| 104 | return self::hostWikiOnlyStrategy(); |
| 105 | } |
| 106 | $crossL = $other->crossLanguageSearchSupported && $this->crossLanguageSearchSupported; |
| 107 | $crossP = $other->crossProjectSearchSupported && $this->crossProjectSearchSupported; |
| 108 | $otherI = $other->extraIndicesSearchSupported && $this->extraIndicesSearchSupported; |
| 109 | if ( $crossL === $crossP && $crossP === $otherI ) { |
| 110 | if ( $crossL ) { |
| 111 | return self::allWikisStrategy(); |
| 112 | } else { |
| 113 | return self::hostWikiOnlyStrategy(); |
| 114 | } |
| 115 | } |
| 116 | return new self( $crossP, $crossL, $otherI ); |
| 117 | } |
| 118 | } |