jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/334715 )
Change subject: Add contentmodel: query feature
......................................................................
Add contentmodel: query feature
Bug: T156371
Change-Id: I54bb866b9d6f39042854c4a56574a4be423d368b
---
M autoload.php
A includes/Query/ContentModelFeature.php
M includes/Searcher.php
3 files changed, 42 insertions(+), 0 deletions(-)
Approvals:
Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
EBernhardson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/autoload.php b/autoload.php
index 73ecdd4..cb56368 100644
--- a/autoload.php
+++ b/autoload.php
@@ -107,6 +107,7 @@
'CirrusSearch\\PhraseSuggesterProfiles' => __DIR__ .
'/profiles/PhraseSuggesterProfiles.php',
'CirrusSearch\\Query\\BaseSimpleKeywordFeatureTest' => __DIR__ .
'/tests/unit/Query/BaseSimpleKeywordFeatureTest.php',
'CirrusSearch\\Query\\BoostTemplatesFeature' => __DIR__ .
'/includes/Query/BoostTemplatesFeature.php',
+ 'CirrusSearch\\Query\\ContentModelFeature' => __DIR__ .
'/includes/Query/ContentModelFeature.php',
'CirrusSearch\\Query\\FileNumericFeature' => __DIR__ .
'/includes/Query/FileNumericFeature.php',
'CirrusSearch\\Query\\FileTypeFeature' => __DIR__ .
'/includes/Query/FileTypeFeature.php',
'CirrusSearch\\Query\\FullTextQueryBuilder' => __DIR__ .
'/includes/Query/FullTextQueryBuilder.php',
diff --git a/includes/Query/ContentModelFeature.php
b/includes/Query/ContentModelFeature.php
new file mode 100644
index 0000000..3f3fb9f
--- /dev/null
+++ b/includes/Query/ContentModelFeature.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace CirrusSearch\Query;
+
+use CirrusSearch\Search\SearchContext;
+use \Elastica\Query;
+
+/**
+ * Content model feature:
+ * contentmodel:wikitext
+ * Selects only articles having this content model.
+ */
+class ContentModelFeature extends SimpleKeywordFeature {
+ /**
+ * @return string[]
+ */
+ protected function getKeywords() {
+ return ['contentmodel'];
+ }
+
+ /**
+ * @param SearchContext $context
+ * @param string $key The keyword
+ * @param string $value The value attached to the keyword with
quotes stripped
+ * @param string $quotedValue The original value in the search
string, including quotes
+ * if used
+ * @param bool $negated Is the search negated? Not used to
generate the returned
+ * AbstractQuery, that will be negated as necessary. Used for any
other building/context
+ * necessary.
+ * @return array Two element array, first an AbstractQuery or null to
apply to the
+ * query. Second a boolean indicating if the quotedValue should be
kept in the search
+ * string.
+ */
+ protected function doApply( SearchContext $context, $key, $value,
$quotedValue, $negated ) {
+ $query = new Query\Match( 'content_model', [ 'query' => $value
] );
+
+ return [ $query, false ];
+ }
+}
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 272fd83..2348a5c 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -335,6 +335,8 @@
new Query\FileTypeFeature(),
// File numeric characteristics - size, resolution, etc.
new Query\FileNumericFeature(),
+ // Content model feature
+ new Query\ContentModelFeature(),
];
$extraFeatures = [];
--
To view, visit https://gerrit.wikimedia.org/r/334715
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I54bb866b9d6f39042854c4a56574a4be423d368b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
Gerrit-Reviewer: Cindy-the-browser-test-bot <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: Tjones <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits