Manybubbles has uploaded a new change for review.
https://gerrit.wikimedia.org/r/75151
Change subject: Reindex pages on template changes.
......................................................................
Reindex pages on template changes.
This uses the LinkUpdateCompleted hook to update the search index after
all links have been updated.
This unfortunately doesn't get to make good use of the bulk api....
Change-Id: I900b510b4403c38b26293ce27fec7c0d4ba93512
---
M CirrusSearch.body.php
M CirrusSearch.php
2 files changed, 21 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/51/75151/1
diff --git a/CirrusSearch.body.php b/CirrusSearch.body.php
index 70a62d6..50a6506 100644
--- a/CirrusSearch.body.php
+++ b/CirrusSearch.body.php
@@ -31,6 +31,13 @@
*/
private static $client = null;
+ /**
+ * Article IDs updated in this process. Used for deduplication of
updates.
+ *
+ * @var array(Integer)
+ */
+ private static $updated = array();
+
public static function getClient() {
if ( self::$client != null ) {
return self::$client;
@@ -283,6 +290,10 @@
public function update( $id, $title, $text ) {
$revision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ), $id
);
$content = $revision->getContent();
+ if ( in_array( $id, CirrusSearch::$updated ) ) {
+ // Already indexed $id
+ return;
+ }
if ( $content->isRedirect() ) {
$target = $content->getUltimateRedirectTarget();
wfDebugLog( 'CirrusSearch', "Updating search index for
$title which is a redirect to " . $target->getText() );
@@ -300,9 +311,18 @@
'rev' => $revision,
'text' => $text
) ) );
+ CirrusSearch::$updated[] = $id;
}
}
+ public static function linksUpdateCompletedHook( $linkUpdate ) {
+ $title = $linkUpdate->getTitle();
+ $articleId = $title->getArticleID();
+ $revision = Revision::loadFromPageId( wfGetDB( DB_SLAVE ),
$articleId );
+ $update = new SearchUpdate( $articleId, $title,
$revision->getContent() );
+ $update->doUpdate();
+ }
+
public function updateTitle( $id, $title ) {
$this->update( $id, $title, null );
}
diff --git a/CirrusSearch.php b/CirrusSearch.php
index 5c8408a..83410ce 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -121,6 +121,7 @@
* Also check Setup for other hooks.
*/
$wgHooks['SearchUpdate'][] = function() { return false; };
+$wgHooks['LinksUpdateComplete'][] = 'CirrusSearch::linksUpdateCompletedHook';
/**
* i18n
--
To view, visit https://gerrit.wikimedia.org/r/75151
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I900b510b4403c38b26293ce27fec7c0d4ba93512
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits