http://www.mediawiki.org/wiki/Special:Code/MediaWiki/58293

Revision: 58293
Author:   maxsem
Date:     2009-10-28 22:26:15 +0000 (Wed, 28 Oct 2009)

Log Message:
-----------
Don't fail with SQL exception if FTS is not supported

Modified Paths:
--------------
    branches/sqlite/includes/search/SearchSqlite.php

Modified: branches/sqlite/includes/search/SearchSqlite.php
===================================================================
--- branches/sqlite/includes/search/SearchSqlite.php    2009-10-28 22:23:02 UTC 
(rev 58292)
+++ branches/sqlite/includes/search/SearchSqlite.php    2009-10-28 22:26:15 UTC 
(rev 58293)
@@ -28,6 +28,9 @@
 class SearchSqlite extends SearchEngine {
        var $strictMatching = true;
 
+       // Cached because SearchUpdate keeps recreating our class
+       private static $fulltextSupported = NULL;
+
        /**
         * Creates an instance of this class
         * @param $db DatabaseSqlite: database object
@@ -36,6 +39,19 @@
                $this->db = $db;
        }
 
+       /**
+        * Whether fulltext search is supported by current schema
+        * @return Boolean
+        */
+       function fulltextSearchSupported() {
+               if ( self::$fulltextSupported === NULL ) {
+                       $res = $this->db->selectField( 'updatelog', 'ul_key', 
array( 'ul_key' => 'fts3' ), __METHOD__ );
+                       self::$fulltextSupported = $res && $this->db->numRows( 
$res ) > 0;
+               }
+               wfDebug( 
"*************************************************************" . 
self::$fulltextSupported . "****************\n" );
+               return self::$fulltextSupported;
+       }
+
        /** 
         * Parse the user's query and transform it into an SQL fragment which 
will 
         * become part of a WHERE clause
@@ -165,7 +181,11 @@
        
        protected function searchInternal( $term, $fulltext ) {
                global $wgSearchMySQLTotalHits;
-               
+
+               if ( !$this->fulltextSearchSupported() ) {
+                       return null;
+               }
+
                $filteredTerm = $this->filter( $term );
                $resultSet = $this->db->query( $this->getQuery( $filteredTerm, 
$fulltext ) );
                
@@ -288,6 +308,9 @@
         * @param $text String
         */
        function update( $id, $title, $text ) {
+               if ( !$this->fulltextSearchSupported() ) {
+                       return;
+               }
                // @todo: find a method to do it in a single request,
                // couldn't do it so far due to typelessness of FTS3 tables.
                $dbw = wfGetDB( DB_MASTER );
@@ -310,6 +333,9 @@
         * @param $title String
         */
     function updateTitle( $id, $title ) {
+               if ( !$this->fulltextSearchSupported() ) {
+                       return;
+               }
                $dbw = wfGetDB( DB_MASTER );
 
                $dbw->update( 'searchindex',



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to