jenkins-bot has submitted this change and it was merged.
Change subject: Use SearchEngine::parseNamespacePrefixes instead of building a
new SearchEngine object
......................................................................
Use SearchEngine::parseNamespacePrefixes instead of building a new SearchEngine
object
Might be useful if we want to unify the way we build keyword features.
Change-Id: Iefed060d75ba6bc69eabfd0e52b70dde73da8870
Depends-On: Iee5bfd1da70b8339a98555ba062bd33b21f0b761
---
M includes/Query/PrefixFeature.php
M includes/Searcher.php
2 files changed, 11 insertions(+), 16 deletions(-)
Approvals:
EBernhardson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Query/PrefixFeature.php b/includes/Query/PrefixFeature.php
index df72d60..70b92cc 100644
--- a/includes/Query/PrefixFeature.php
+++ b/includes/Query/PrefixFeature.php
@@ -2,8 +2,7 @@
namespace CirrusSearch\Query;
-use CirrusSearch;
-use CirrusSearch\Connection;
+use SearchEngine;
use CirrusSearch\Search\SearchContext;
/**
@@ -22,15 +21,6 @@
* prefix:"California Cou"
*/
class PrefixFeature implements KeywordFeature {
-
- /**
- * @var Connection
- */
- private $connection;
-
- public function __construct( Connection $conn ) {
- $this->connection = $conn;
- }
/**
* @param SearchContext $context
@@ -55,10 +45,15 @@
// Suck namespaces out of $value. Note that this overrides
provided
// namespace filters.
- $cirrusSearchEngine = new CirrusSearch();
- $cirrusSearchEngine->setConnection( $this->connection );
- $value = trim( $cirrusSearchEngine->replacePrefixes( $value ) );
- $context->setNamespaces( $cirrusSearchEngine->namespaces );
+ $queryAndNamespace = SearchEngine::parseNamespacePrefixes(
$value );
+ if ( $queryAndNamespace === false ) {
+ // If no namespaces is extracted we force to NS_MAIN
+ $context->setNamespaces( [ NS_MAIN ] );
+ } else {
+ $value = $queryAndNamespace[0];
+ $context->setNamespaces( $queryAndNamespace[1] );
+ }
+ $value = trim( $value );
// If the namespace prefix wasn't the entire prefix filter then
add a filter for the title
if ( strpos( $value, ':' ) !== strlen( $value ) - 1 ) {
diff --git a/includes/Searcher.php b/includes/Searcher.php
index abe99cf..3b8389b 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -310,7 +310,7 @@
$this->escaper,
[
// Handle title prefix notation
- new Query\PrefixFeature( $this->connection ),
+ new Query\PrefixFeature(),
// Handle prefer-recent keyword
new Query\PreferRecentFeature( $this->config ),
// Handle local keyword
--
To view, visit https://gerrit.wikimedia.org/r/311420
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iefed060d75ba6bc69eabfd0e52b70dde73da8870
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
Gerrit-Reviewer: Cindy-the-browser-test-bot <[email protected]>
Gerrit-Reviewer: DCausse <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: Smalyshev <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits