Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
84.38% |
27 / 32 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
FullTextKeywordRegistry | |
84.38% |
27 / 32 |
|
50.00% |
1 / 2 |
5.10 | |
0.00% |
0 / 1 |
__construct | |
83.87% |
26 / 31 |
|
0.00% |
0 / 1 |
4.07 | |||
getKeywords | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Parser; |
4 | |
5 | use CirrusSearch\CirrusSearchHookRunner; |
6 | use CirrusSearch\Query\BoostTemplatesFeature; |
7 | use CirrusSearch\Query\ContentModelFeature; |
8 | use CirrusSearch\Query\DeepcatFeature; |
9 | use CirrusSearch\Query\FileTypeFeature; |
10 | use CirrusSearch\Query\HasTemplateFeature; |
11 | use CirrusSearch\Query\InCategoryFeature; |
12 | use CirrusSearch\Query\IndexedNumericFieldFeature; |
13 | use CirrusSearch\Query\InSourceFeature; |
14 | use CirrusSearch\Query\InTitleFeature; |
15 | use CirrusSearch\Query\KeywordFeature; |
16 | use CirrusSearch\Query\LanguageFeature; |
17 | use CirrusSearch\Query\LinksToFeature; |
18 | use CirrusSearch\Query\LocalFeature; |
19 | use CirrusSearch\Query\MoreLikeFeature; |
20 | use CirrusSearch\Query\MoreLikeThisFeature; |
21 | use CirrusSearch\Query\PageIdFeature; |
22 | use CirrusSearch\Query\PreferRecentFeature; |
23 | use CirrusSearch\Query\PrefixFeature; |
24 | use CirrusSearch\Query\SimpleKeywordFeature; |
25 | use CirrusSearch\Query\SubPageOfFeature; |
26 | use CirrusSearch\Query\TextFieldFilterFeature; |
27 | use CirrusSearch\SearchConfig; |
28 | use MediaWiki\Logger\LoggerFactory; |
29 | use MediaWiki\MediaWikiServices; |
30 | use MediaWiki\Sparql\SparqlClient; |
31 | |
32 | /** |
33 | * Registry of keywords suited for fulltext searches |
34 | */ |
35 | class FullTextKeywordRegistry implements KeywordRegistry { |
36 | /** |
37 | * @var KeywordFeature[] |
38 | */ |
39 | private $features; |
40 | |
41 | /** |
42 | * @param SearchConfig $config |
43 | * @param CirrusSearchHookRunner|null $cirrusSearchHookRunner |
44 | * @param NamespacePrefixParser|null $namespacePrefixParser |
45 | * @param SparqlClient|null $client |
46 | */ |
47 | public function __construct( |
48 | SearchConfig $config, |
49 | ?CirrusSearchHookRunner $cirrusSearchHookRunner = null, |
50 | ?NamespacePrefixParser $namespacePrefixParser = null, |
51 | ?SparqlClient $client = null |
52 | ) { |
53 | $this->features = [ |
54 | // Handle morelike keyword (greedy). Kept for BC reasons with existing clients. |
55 | // The morelikethis keyword should be preferred. |
56 | new MoreLikeFeature( $config ), |
57 | // Handle title prefix notation (greedy). Kept for BC reasons with existing clients. |
58 | // The subpageof keyword should be preferred. |
59 | new PrefixFeature( $namespacePrefixParser ), |
60 | // Handle prefer-recent keyword |
61 | new PreferRecentFeature( $config ), |
62 | // Handle local keyword |
63 | new LocalFeature(), |
64 | // Handle boost-templates keyword |
65 | new BoostTemplatesFeature(), |
66 | // Handle hastemplate keyword |
67 | new HasTemplateFeature(), |
68 | // Handle linksto keyword |
69 | new LinksToFeature(), |
70 | // Handle incategory keyword |
71 | new InCategoryFeature( $config ), |
72 | // Handle non-regex insource keyword |
73 | new InSourceFeature( $config ), |
74 | // Handle intitle keyword |
75 | new InTitleFeature( $config ), |
76 | // inlanguage keyword |
77 | new LanguageFeature(), |
78 | // File types |
79 | new FileTypeFeature( $config ), |
80 | // File mime types |
81 | new TextFieldFilterFeature( 'filemime', 'file_mime' ), |
82 | // File numeric characteristics - size, resolution, etc. |
83 | new IndexedNumericFieldFeature(), |
84 | // Content model feature |
85 | new ContentModelFeature(), |
86 | // subpageof keyword |
87 | new SubPageOfFeature(), |
88 | // deepcat feature |
89 | new DeepcatFeature( $config, $client ), |
90 | // morelikethis feature: a non-greedy version of the morelike keyword. |
91 | new MoreLikeThisFeature( $config ), |
92 | // ids query |
93 | new PageIdFeature() |
94 | ]; |
95 | |
96 | $extraFeatures = []; |
97 | $cirrusSearchHookRunner = $cirrusSearchHookRunner ?: new CirrusSearchHookRunner( |
98 | MediaWikiServices::getInstance()->getHookContainer() ); |
99 | $cirrusSearchHookRunner->onCirrusSearchAddQueryFeatures( $config, $extraFeatures ); |
100 | foreach ( $extraFeatures as $extra ) { |
101 | if ( $extra instanceof SimpleKeywordFeature ) { |
102 | $this->features[] = $extra; |
103 | } else { |
104 | LoggerFactory::getInstance( 'CirrusSearch' ) |
105 | ->warning( 'Skipped invalid feature of class ' . get_class( $extra ) . |
106 | ' - should be instanceof SimpleKeywordFeature' ); |
107 | } |
108 | } |
109 | } |
110 | |
111 | /** |
112 | * @return KeywordFeature[] |
113 | */ |
114 | public function getKeywords() { |
115 | return $this->features; |
116 | } |
117 | } |