Phoenix303 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/199666
Change subject: Reindex tool to update indexes
......................................................................
Reindex tool to update indexes
Rebuild index from scratch.
Run: php scripts/ttmserver-export.php --reindex
Change-Id: I0a7bb626dd982be68a2246e97eb876a1223e428a
---
M scripts/ttmserver-export.php
M ttmserver/ElasticSearchTTMServer.php
2 files changed, 31 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/66/199666/1
diff --git a/scripts/ttmserver-export.php b/scripts/ttmserver-export.php
index 671e402..1737a27 100644
--- a/scripts/ttmserver-export.php
+++ b/scripts/ttmserver-export.php
@@ -23,6 +23,8 @@
class TTMServerBootstrap extends Maintenance {
/// @var Array Configuration of requested TTMServer
protected $config;
+ // Option for reindexing
+ protected $reindex;
public function __construct() {
parent::__construct();
@@ -39,6 +41,9 @@
/*required*/false,
/*has arg*/true
);
+ $this->addOption( 'reindex',
+ 'Rebuild the index '
+ );
$this->setBatchSize( 500 );
$this->start = microtime( true );
}
@@ -60,6 +65,7 @@
}
$config = $wgTranslateTranslationServices[$configKey];
+ $this->reindex = $this->getOption( 'reindex', false );
// Do as little as possible in the main thread, to not clobber
forked processes.
// See also #resetStateForFork.
@@ -126,6 +132,7 @@
$this->statusLine( "Cleaning up old entries...\n" );
$server = TTMServer::factory( $config );
$server->setLogger( $this );
+ $server->setReindex( $this->reindex );
$server->beginBootstrap();
}
diff --git a/ttmserver/ElasticSearchTTMServer.php
b/ttmserver/ElasticSearchTTMServer.php
index e376764..e3b3228 100644
--- a/ttmserver/ElasticSearchTTMServer.php
+++ b/ttmserver/ElasticSearchTTMServer.php
@@ -26,6 +26,10 @@
* Reference to the maintenance script to relay logging output.
*/
protected $logger;
+ /**
+ * Used for Reindex
+ */
+ protected $reindex = false;
public function isLocalSuggestion( array $suggestion ) {
return $suggestion['wiki'] === wfWikiId();
@@ -274,18 +278,28 @@
return new \Elastica\Document( $globalid, $data );
}
-
- public function beginBootstrap() {
+ /*
+ * Create index
+ */
+ public function createIndex( $rebuild ) {
$type = $this->getType();
-
- if ( !$type->getIndex()->exists() ) {
- $type->getIndex()->create(
+ $type->getIndex()->create(
array(
'number_of_shards' =>
$this->getShardCount(),
'number_of_replicas' =>
$this->getReplicaCount(),
),
- false /* Do not drop the index if exists */
+ $rebuild
);
+ }
+
+ public function beginBootstrap() {
+ if ( $this->reindex ){
+ $this->logOutput( 'Rebuilding the index ...' );
+ $this->createIndex( true );
+ }
+ $type = $this->getType();
+ if ( !$type->getIndex()->exists() ) {
+ $this->createIndex( false );
}
$settings = $type->getIndex()->getSettings();
@@ -430,6 +444,10 @@
}
}
+ public function setReindex( $reindex ) {
+ $this->reindex = $reindex;
+ }
+
// Search interface
public function search( $queryString, $opts, $highlight ) {
$query = new \Elastica\Query();
--
To view, visit https://gerrit.wikimedia.org/r/199666
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a7bb626dd982be68a2246e97eb876a1223e428a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Phoenix303 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits