Database search fixes:
authorChad Horohoe <chadh@wikimedia.org>
Fri, 20 Jun 2014 20:43:36 +0000 (13:43 -0700)
committerChad Horohoe <chadh@wikimedia.org>
Fri, 20 Jun 2014 20:43:36 +0000 (13:43 -0700)
- Move filter() function and make it protected, nothing uses it
  outside database-backed searching
- Use per-backend legal search characters rather than assuming the
  static implementation is right

Change-Id: Ic2b830b56137b2dfe68b9b9c3de012151e716952

includes/deferred/SearchUpdate.php
includes/search/SearchDatabase.php
includes/search/SearchEngine.php

index 9ae9034..20f348a 100644 (file)
@@ -81,10 +81,10 @@ class SearchUpdate implements DeferrableUpdate {
                wfProfileIn( __METHOD__ );
 
                $page = WikiPage::newFromId( $this->id, WikiPage::READ_LATEST );
-               $indexTitle = $this->indexTitle();
 
                foreach ( SearchEngine::getSearchTypes() as $type ) {
                        $search = SearchEngine::create( $type );
+                       $indexTitle = $this->indexTitle( $search );
                        if ( !$search->supports( 'search-update' ) ) {
                                continue;
                        }
@@ -181,13 +181,13 @@ class SearchUpdate implements DeferrableUpdate {
         *
         * @return string A stripped-down title string ready for the search index
         */
-       private function indexTitle() {
+       private function indexTitle( SearchEngine $search ) {
                global $wgContLang;
 
                $ns = $this->title->getNamespace();
                $title = $this->title->getText();
 
-               $lc = SearchEngine::legalSearchChars() . '&#;';
+               $lc = $search->legalSearchChars() . '&#;';
                $t = $wgContLang->normalizeForSearch( $title );
                $t = preg_replace( "/[^{$lc}]+/", ' ', $t );
                $t = $wgContLang->lc( $t );
index e3aafe8..82d0907 100644 (file)
@@ -43,4 +43,15 @@ class SearchDatabase extends SearchEngine {
                        $this->db = wfGetDB( DB_SLAVE );
                }
        }
+
+       /**
+        * Return a 'cleaned up' search string
+        *
+        * @param string $text
+        * @return string
+        */
+       protected function filter( $text ) {
+               $lc = $this->legalSearchChars();
+               return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
+       }
 }
index 3a3baef..d8c6f6d 100644 (file)
@@ -419,17 +419,6 @@ class SearchEngine {
                return $formatted;
        }
 
-       /**
-        * Return a 'cleaned up' search string
-        *
-        * @param string $text
-        * @return string
-        */
-       function filter( $text ) {
-               $lc = $this->legalSearchChars();
-               return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
-       }
-
        /**
         * Load up the appropriate search engine class for the currently
         * active database backend, and return a configured instance.