[MediaWiki-commits] [Gerrit] mediawiki...CirrusSearch[master]: Add support for 'super_detect_noop' script language

2017-10-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/376012 )

Change subject: Add support for 'super_detect_noop' script language
..


Add support for 'super_detect_noop' script language

This is because native scripts have been deprecated.
Requires a config change and the extra version 5.5.2

Should be merged once elastic 5.5.2 is deployed or if
the super_detect_noop_enable_native has been set to true.

Bug: T174652
Change-Id: Ia3e5b507080bfe8a4d3075e67adac3d9c5b61ee9
---
M CirrusSearch.php
M README
M docs/settings.txt
M includes/Updater.php
M tests/jenkins/FullyFeaturedConfig.php
M tests/unit/UpdaterTest.php
6 files changed, 33 insertions(+), 6 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

Objections:
  DCausse: There's a problem with this change, please improve



diff --git a/CirrusSearch.php b/CirrusSearch.php
index 1f6e140..6cc7508 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -176,6 +176,12 @@
  * wikimedia-extra versions 1.3.1, 1.4.2, 1.5.0, and greater:
  * $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop' ] = true;
  *
+ * As of elastic 5.5 native scripts have been deprecated the super_detect_noop 
is
+ * now available as a normal script with language "super_detect_noop".
+ * If you run elastic prior to 5.5.2 you must enable this option if using
+ * super_detect_noop.
+ * $wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_enable_native'] = 
true;
+ *
  * Controls the list of extra handlers to set when the noop script
  * is enabled.
  *
diff --git a/README b/README
index 535b455..24f85ce 100644
--- a/README
+++ b/README
@@ -13,6 +13,8 @@
   $CirrusSearchElasticQuirks = [ 'query_string_max_determinized_states' => 
true ];
 - elastic versions before 5.3.1 suffer from a bug that prevent an index to be 
reindexed
   properly without missing docs when using multiple elasticsearch machines
+- when using elastic prior to 5.5.2 with the extra plugin and the 
super_detect_noop script
+  you must activate the "super_detect_noop_enable_native" option (see 
docs/settings.txt)
 
 Place the CirrusSearch extension in your extensions directory.
 Make sure you have the curl php library installed (sudo apt-get install 
php5-curl in Debian.)
diff --git a/docs/settings.txt b/docs/settings.txt
index cfabeed..5a44679 100644
--- a/docs/settings.txt
+++ b/docs/settings.txt
@@ -171,6 +171,13 @@
 
 $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop' ] = true;
 
+As of elastic 5.5 native scripts have been deprecated the super_detect_noop is
+now available as a normal script with language "super_detect_noop".
+If you run elastic prior to 5.5.2 you must enable this option if using
+super_detect_noop.
+
+$wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_enable_native'] = 
true;
+
 Configure field specific handlers for the noop script.
 
 $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop_handlers' ] = [
diff --git a/includes/Updater.php b/includes/Updater.php
index 8a2ad19..8c62ea7 100644
--- a/includes/Updater.php
+++ b/includes/Updater.php
@@ -198,9 +198,9 @@
$allData = array_fill_keys( 
$this->connection->getAllIndexTypes(), [] );
foreach ( $this->buildDocumentsForPages( $pages, $flags ) as 
$document ) {
$suffix = 
$this->connection->getIndexSuffixForNamespace( $document->get( 'namespace' ) );
-   if ( isset( $wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) &&
-   $wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) {
-   $document = $this->docToSuperDetectNoopScript( 
$document );
+   if ( isset( $wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) ) {
+   $document = $this->docToSuperDetectNoopScript( 
$document,
+   !empty( 
$wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_enable_native' ] ) );
}
// TODO: Move hints reset at a later stage if they 
appear to be useful
// (e.g. in DataSender::sendData)
@@ -403,9 +403,10 @@
 * 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
+* @param bool $enableNative enable the use of native scripts 
(deprecated as of elastic 5.5+)
 * @return \Elastica\Script\Script
 */
-   public function docToSuperDetectNoopScript( $doc ) {
+   public function docToSuperDetectNoopScript( $doc, $enableNative = false 
) {
$handlers = CirrusIndexField::getHint( $doc, 
CirrusIndexField::NOOP_HINT );

[MediaWiki-commits] [Gerrit] mediawiki...CirrusSearch[master]: Add support for 'super_detect_noop' script language

2017-09-05 Thread DCausse (Code Review)
DCausse has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376012 )

Change subject: Add support for 'super_detect_noop' script language
..

Add support for 'super_detect_noop' script language

This is because native scripts have been deprecated.
Requires a config change and the extra version 5.5.2

Bug: T174652
Change-Id: Ia3e5b507080bfe8a4d3075e67adac3d9c5b61ee9
---
M CirrusSearch.php
M docs/settings.txt
M includes/Updater.php
M tests/unit/UpdaterTest.php
4 files changed, 32 insertions(+), 4 deletions(-)


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

diff --git a/CirrusSearch.php b/CirrusSearch.php
index 1f6e140..61672a4 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -176,6 +176,12 @@
  * wikimedia-extra versions 1.3.1, 1.4.2, 1.5.0, and greater:
  * $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop' ] = true;
  *
+ * As of elastic 5.5 native scripts have been deprecated the super_detect_noop 
is
+ * now available as a normal script with language "super_detect_noop".
+ * In order to use it and turn off native script usage use this option 
(requires
+ * elastic 5.5+):
+ * $wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_disable_native'] = 
true;
+ *
  * Controls the list of extra handlers to set when the noop script
  * is enabled.
  *
diff --git a/docs/settings.txt b/docs/settings.txt
index cfabeed..abee1de 100644
--- a/docs/settings.txt
+++ b/docs/settings.txt
@@ -171,6 +171,13 @@
 
 $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop' ] = true;
 
+As of elastic 5.5 native scripts have been deprecated the super_detect_noop is
+now available as a normal script with language "super_detect_noop".
+In order to use it and turn off native script usage use this option (requires
+elastic 5.5+):
+
+$wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_disable_native'] = 
true;
+
 Configure field specific handlers for the noop script.
 
 $wgCirrusSearchWikimediaExtraPlugin[ 'super_detect_noop_handlers' ] = [
diff --git a/includes/Updater.php b/includes/Updater.php
index 8a2ad19..f4dcee9 100644
--- a/includes/Updater.php
+++ b/includes/Updater.php
@@ -200,7 +200,12 @@
$suffix = 
$this->connection->getIndexSuffixForNamespace( $document->get( 'namespace' ) );
if ( isset( $wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) &&
$wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) {
-   $document = $this->docToSuperDetectNoopScript( 
$document );
+   $disableNative = false;
+   if ( isset( 
$wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_disable_native'] ) &&
+   
$wgCirrusSearchWikimediaExtraPlugin['super_detect_noop_disable_native'] ) {
+   $disableNative = true;
+   }
+   $document = $this->docToSuperDetectNoopScript( 
$document, $disableNative );
}
// TODO: Move hints reset at a later stage if they 
appear to be useful
// (e.g. in DataSender::sendData)
@@ -403,9 +408,10 @@
 * 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
+* @param bool $disableNative disable the use of native scripts 
(requires elastic 5.5)
 * @return \Elastica\Script\Script
 */
-   public function docToSuperDetectNoopScript( $doc ) {
+   public function docToSuperDetectNoopScript( $doc, $disableNative ) {
$handlers = CirrusIndexField::getHint( $doc, 
CirrusIndexField::NOOP_HINT );
$params = $doc->getParams();
$params['source'] = $doc->getData();
@@ -421,7 +427,11 @@
$params['handlers'] += $extraHandlers;
}
 
-   $script = new \Elastica\Script\Script( 'super_detect_noop', 
$params, 'native' );
+   if ( $disableNative ) {
+   $script = new \Elastica\Script\Script( 
'super_detect_noop', $params, 'super_detect_noop' );
+   } else {
+   $script = new \Elastica\Script\Script( 
'super_detect_noop', $params, 'native' );
+   }
if ( $doc->getDocAsUpsert() ) {
CirrusIndexField::resetHints( $doc );
$script->setUpsert( $doc );
diff --git a/tests/unit/UpdaterTest.php b/tests/unit/UpdaterTest.php
index 17de8c5..9b593da 100644
--- a/tests/unit/UpdaterTest.php
+++ b/tests/unit/UpdaterTest.php
@@ -33,7 +33,12 @@
$conn = new Connection( $config );