jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/347380 )

Change subject: Allow setting super_noop_script handlers
......................................................................


Allow setting super_noop_script handlers

Adds a new key in the existing $wgCirrusSearchWikimediaExtraPlugin to
allow setting addition handlers for the noop script.

Bug: T160926
Change-Id: I28d8b1be5bdc9e3422cfc24a9aedd801b03b2ff7
---
M CirrusSearch.php
M docs/settings.txt
M includes/Updater.php
A tests/unit/UpdaterTest.php
4 files changed, 119 insertions(+), 1 deletion(-)

Approvals:
  Smalyshev: Looks good to me, approved
  Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/CirrusSearch.php b/CirrusSearch.php
index 6792629..d1cf1a7 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -151,6 +151,13 @@
 // wikimedia-extra versions 1.3.1, 1.4.2, 1.5.0, and greater:
 // $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop' ] = true;
 //
+// Controls the list of extra handlers to set when the noop script
+// is enabled.
+//
+// $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop_handlers' ] = [
+//    'labels' => 'equals'
+// ];
+//
 // This turns on document level noop-detection for updates based on revision
 // ids and is compatible with wikimedia-extra versions 2.3.4.1 and greater:
 // $wgCirrusSearchWikimediaExtraPlugin[ 'documentVersion' ] = true
diff --git a/docs/settings.txt b/docs/settings.txt
index 1968ffc..732051e 100644
--- a/docs/settings.txt
+++ b/docs/settings.txt
@@ -171,6 +171,12 @@
 
     $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop' ] = true;
 
+Configure field specific handlers for the noop script.
+
+    $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop_handlers' ] = [
+        'labels' => 'equals',
+    ];
+
 This turns on document level noop-detection for updates based on revision
 ids and is compatible with wikimedia-extra versions 2.3.4.1 and greater:
 
diff --git a/includes/Updater.php b/includes/Updater.php
index 9fe1108..8758245 100644
--- a/includes/Updater.php
+++ b/includes/Updater.php
@@ -390,18 +390,25 @@
 
        /**
         * Converts a document into a call to super_detect_noop from the 
wikimedia-extra plugin.
+        * @internal made public for testing purposes
         * @param \Elastica\Document $doc
         * @return \Elastica\Script\Script
         */
-       private function docToSuperDetectNoopScript( $doc ) {
+       public function docToSuperDetectNoopScript( $doc ) {
                $params = $doc->getParams();
                $params['source'] = $doc->getData();
+
                $params['handlers'] = [
                        'incoming_links' => 'within 20%',
                ];
+               $extraHandlers = $this->searchConfig->getElement( 
'CirrusSearchWikimediaExtraPlugin', 'super_detect_noop_handlers' );
+               if ( is_array( $extraHandlers ) ) {
+                       $params['handlers'] += $extraHandlers;
+               }
                // Added in search-extra 2.3.4.1, around sept 2015. This check 
can be dropped
                // and may default sometime in the future when users are 
certain to be using
                // a version of the search-extra plugin with document 
versioning support
+               // TODO: possibly deprecate this config in favor of 
super_detect_noop_handlers
                if ( $this->searchConfig->getElement( 
'CirrusSearchWikimediaExtraPlugin', 'documentVersion' ) ) {
                        $params['handlers']['version'] = 'documentVersion';
                }
diff --git a/tests/unit/UpdaterTest.php b/tests/unit/UpdaterTest.php
new file mode 100644
index 0000000..44f75a4
--- /dev/null
+++ b/tests/unit/UpdaterTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace CirrusSearch;
+
+use CirrusSearch\Test\HashSearchConfig;
+
+/**
+ * Test Updater methods
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @group CirrusSearch
+ */
+class UpdaterTest extends CirrusTestCase {
+       /**
+        * @dataProvider provideDocs
+        */
+       public function testSuperNoopExtraHandlers( array $rawDoc, array 
$extraHandlers, array $expectedParams ) {
+               $config = $this->buildConfig( $extraHandlers );
+               $conn = new Connection( $config );
+               $updater = new Updater( $conn, $config );
+               $doc = $this->builDoc( $rawDoc );
+               $script = $updater->docToSuperDetectNoopScript( $doc );
+               $this->assertEquals( $expectedParams['handlers'], 
$script->getParams()['handlers'] );
+               $this->assertEquals( $expectedParams['_source'], 
$script->getParams()['source'] );
+       }
+
+       public static function provideDocs() {
+               return [
+                       'simple' => [
+                               [
+                                       123 => [ 'title' => 'test' ]
+                               ],
+                               [
+                                       'labels' => 'equals',
+                                       'version' => 'documentVersion',
+                               ],
+                               [
+                                       'handlers' => [
+                                               'incoming_links' => 'within 
20%',
+                                               'labels' => 'equals',
+                                               'version' => 'documentVersion',
+                                       ],
+                                       '_source' => [
+                                               'title' => 'test',
+                                       ],
+                               ],
+                       ],
+                       'do not override' => [
+                               [
+                                       123 => [ 'title' => 'test' ]
+                               ],
+                               [
+                                       'labels' => 'equals',
+                                       'version' => 'documentVersion',
+                                       'incoming_links' => 'within 30%',
+                               ],
+                               [
+                                       'handlers' => [
+                                               'incoming_links' => 'within 
20%',
+                                               'labels' => 'equals',
+                                               'version' => 'documentVersion',
+                                       ],
+                                       '_source' => [
+                                               'title' => 'test',
+                                       ],
+                               ],
+                       ],
+               ];
+       }
+
+       private function buildConfig( array $extraHandlers ) {
+               return new HashSearchConfig( [
+                       'CirrusSearchWikimediaExtraPlugin' => [
+                               'super_detect_noop' => true,
+                               'super_detect_noop_handlers' => $extraHandlers,
+                       ],
+               ], [ 'inherit' ] );
+       }
+
+       private function builDoc( array $doc ) {
+               reset( $doc );
+               return new \Elastica\Document( key( $doc ), reset( $doc ) );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/347380
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I28d8b1be5bdc9e3422cfc24a9aedd801b03b2ff7
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: 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

Reply via email to