DCausse has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311420

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, 8 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/20/311420/1

diff --git a/includes/Query/PrefixFeature.php b/includes/Query/PrefixFeature.php
index df72d60..3b46fb5 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;
 
 /**
@@ -23,13 +22,7 @@
  */
 class PrefixFeature implements KeywordFeature {
 
-       /**
-        * @var Connection
-        */
-       private $connection;
-
-       public function __construct( Connection $conn ) {
-               $this->connection = $conn;
+       public function __construct() {
        }
 
        /**
@@ -55,10 +48,11 @@
 
                // 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 ) {
+                       $value = trim( $queryAndNamespace[0] );
+                       $context->setNamespaces( $queryAndNamespace[1] );
+               }
 
                // 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: newchange
Gerrit-Change-Id: Iefed060d75ba6bc69eabfd0e52b70dde73da8870
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <dcau...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to