jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Demon: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CirrusSearch.body.php b/CirrusSearch.body.php
index 5ef2cbe..935f7c5 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: merged
Gerrit-Change-Id: I900b510b4403c38b26293ce27fec7c0d4ba93512
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to