From: daniel Date: Thu, 13 Dec 2012 20:48:36 +0000 (+0100) Subject: make rebuildtextindex script aware of content models. X-Git-Tag: 1.31.0-rc.0~21260^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=0be16d1d77025ef5c026c88e119cdcbdebb0270a;p=lhc%2Fweb%2Fwiklou.git make rebuildtextindex script aware of content models. Change-Id: Ia976ce975e3c64a54e1d4b27c52bccaa07754041 --- diff --git a/includes/search/SearchUpdate.php b/includes/search/SearchUpdate.php index 40dd36c23d..389c317499 100644 --- a/includes/search/SearchUpdate.php +++ b/includes/search/SearchUpdate.php @@ -34,7 +34,12 @@ class SearchUpdate implements DeferrableUpdate { private $mTitleWords; function __construct( $id, $title, $text = false ) { - $nt = Title::newFromText( $title ); + if ( is_string( $title ) ) { + $nt = Title::newFromText( $title ); + } else { + $nt = $title; + } + if( $nt ) { $this->mId = $id; $this->mText = $text; diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index 41b245f81e..e5b08f8e3e 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -86,28 +86,45 @@ class RebuildTextIndex extends Maintenance { * Populates the search index with content from all pages */ protected function populateSearchIndex() { + global $wgContentHandlerUseDB; + $res = $this->db->select( 'page', 'MAX(page_id) AS count' ); $s = $this->db->fetchObject( $res ); $count = $s->count; $this->output( "Rebuilding index fields for {$count} pages...\n" ); $n = 0; + $fields = array_merge( + Revision::selectPageFields(), + Revision::selectFields(), + Revision::selectTextFields() + ); + while ( $n < $count ) { if ( $n ) { $this->output( $n . "\n" ); } $end = $n + self::RTI_CHUNK_SIZE - 1; - $res = $this->db->select( array( 'page', 'revision', 'text' ), - array( 'page_id', 'page_namespace', 'page_title', 'old_flags', 'old_text' ), + $res = $this->db->select( array( 'page', 'revision', 'text' ), $fields, array( "page_id BETWEEN $n AND $end", 'page_latest = rev_id', 'rev_text_id = old_id' ), __METHOD__ - ); + ); foreach ( $res as $s ) { - $revtext = Revision::getRevisionText( $s ); - $u = new SearchUpdate( $s->page_id, $s->page_title, $revtext ); - $u->doUpdate(); + try { + $title = Title::makeTitle( $s->page_namespace, $s->page_title ); + + $rev = new Revision( $s ); + $content = $rev->getContent(); + $text = $content->getTextForSearchIndex(); + + $u = new SearchUpdate( $s->page_id, $title, $text ); + $u->doUpdate(); + } catch ( MWContentSerializationException $ex ) { + $this->output( "Failed to deserialize content of revision {$s->rev_id} of page " + . "`" . $title->getPrefixedDBkey() . "`!\n" ); + } } $n += self::RTI_CHUNK_SIZE; }