Fix log type and name in revdeleted messages: suppressions are stored in the suppress...
[lhc/web/wiklou.git] / includes / SearchMySQL.php
index f9b71c8..78aa60f 100644 (file)
@@ -34,7 +34,10 @@ class SearchMySQL extends SearchEngine {
                $this->db = $db;
        }
 
-       /** @todo document */
+       /** 
+        * Parse the user's query and transform it into an SQL fragment which will 
+        * become part of a WHERE clause
+        */
        function parseQuery( $filteredText, $fulltext ) {
                global $wgContLang;
                $lc = SearchEngine::legalSearchChars(); // Minus format chars
@@ -50,11 +53,24 @@ class SearchMySQL extends SearchEngine {
                                if( $this->strictMatching && ($terms[1] == '') ) {
                                        $terms[1] = '+';
                                }
-                               $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
+                               // Search terms in all variant forms, only
+                               // apply on wiki with LanguageConverter
+                               $temp_terms = $wgContLang->autoConvertToAllVariants( $terms[2] );
+                               if( is_array( $temp_terms )) {
+                                       $temp_terms = array_unique( array_values( $temp_terms ));
+                                       foreach( $temp_terms as $t )
+                                               $searchon .= $terms[1] . $wgContLang->stripForSearch( $t ) . ' ';
+                               }
+                               else
+                                       $searchon .= $terms[1] . $wgContLang->stripForSearch( $terms[2] );
                                if( !empty( $terms[3] ) ) {
                                        // Match individual terms in result highlighting...
                                        $regexp = preg_quote( $terms[3], '/' );
-                                       if( $terms[4] ) $regexp .= "[0-9A-Za-z_]+";
+                                       if( $terms[4] ) {
+                                               $regexp = "\b$regexp"; // foo*
+                                       } else {
+                                               $regexp = "\b$regexp\b";
+                                       }
                                } else {
                                        // Match the quoted term in result highlighting...
                                        $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
@@ -79,9 +95,8 @@ class SearchMySQL extends SearchEngine {
        /**
         * Perform a full text search query and return a result set.
         *
-        * @param string $term - Raw search term
+        * @param $term String: raw search term
         * @return MySQLSearchResultSet
-        * @access public
         */
        function searchText( $term ) {
                $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
@@ -91,9 +106,8 @@ class SearchMySQL extends SearchEngine {
        /**
         * Perform a title-only search query and return a result set.
         *
-        * @param string $term - Raw search term
+        * @param $term String: raw search term
         * @return MySQLSearchResultSet
-        * @access public
         */
        function searchTitle( $term ) {
                $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
@@ -103,8 +117,7 @@ class SearchMySQL extends SearchEngine {
 
        /**
         * Return a partial WHERE clause to exclude redirects, if so set
-        * @return string
-        * @private
+        * @return String
         */
        function queryRedirect() {
                if( $this->showRedirects ) {
@@ -116,23 +129,22 @@ class SearchMySQL extends SearchEngine {
 
        /**
         * Return a partial WHERE clause to limit the search to the given namespaces
-        * @return string
-        * @private
+        * @return String
         */
        function queryNamespaces() {
                if( is_null($this->namespaces) )
                        return '';  # search all
-               $namespaces = implode( ',', $this->namespaces );
-               if ($namespaces == '') {
+               if ( !count( $this->namespaces ) ) {
                        $namespaces = '0';
+               } else {
+                       $namespaces = $this->db->makeList( $this->namespaces );
                }
                return 'AND page_namespace IN (' . $namespaces . ')';
        }
 
        /**
         * Return a LIMIT clause to limit results on the query.
-        * @return string
-        * @private
+        * @return String
         */
        function queryLimit() {
                return $this->db->limitResult( '', $this->limit, $this->offset );
@@ -141,8 +153,7 @@ class SearchMySQL extends SearchEngine {
        /**
         * Does not do anything for generic search engine
         * subclasses may define this though
-        * @return string
-        * @private
+        * @return String
         */
        function queryRanking( $filteredTerm, $fulltext ) {
                return '';
@@ -151,9 +162,8 @@ class SearchMySQL extends SearchEngine {
        /**
         * Construct the full SQL query to do the search.
         * The guts shoulds be constructed in queryMain()
-        * @param string $filteredTerm
-        * @param bool $fulltext
-        * @private
+        * @param $filteredTerm String
+        * @param $fulltext Boolean
         */
        function getQuery( $filteredTerm, $fulltext ) {
                return $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
@@ -166,8 +176,8 @@ class SearchMySQL extends SearchEngine {
 
        /**
         * Picks which field to index on, depending on what type of query.
-        * @param bool $fulltext
-        * @return string
+        * @param $fulltext Boolean
+        * @return String
         */
        function getIndexField( $fulltext ) {
                return $fulltext ? 'si_text' : 'si_title';
@@ -179,10 +189,9 @@ class SearchMySQL extends SearchEngine {
         * version; MySQL 3 and MySQL 4 have different capabilities
         * in their fulltext search indexes.
         *
-        * @param string $filteredTerm
-        * @param bool $fulltext
-        * @return string
-        * @private
+        * @param $filteredTerm String
+        * @param $fulltext Boolean
+        * @return String
         */
        function queryMain( $filteredTerm, $fulltext ) {
                $match = $this->parseQuery( $filteredTerm, $fulltext );
@@ -197,9 +206,9 @@ class SearchMySQL extends SearchEngine {
         * Create or update the search index record for the given page.
         * Title and text should be pre-processed.
         *
-        * @param int $id
-        * @param string $title
-        * @param string $text
+        * @param $id Integer
+        * @param $title String
+        * @param $text String
         */
        function update( $id, $title, $text ) {
                $dbw = wfGetDB( DB_MASTER );
@@ -216,8 +225,8 @@ class SearchMySQL extends SearchEngine {
         * Update a search index record's title only.
         * Title should be pre-processed.
         *
-        * @param int $id
-        * @param string $title
+        * @param $id Integer
+        * @param $title String
         */
     function updateTitle( $id, $title ) {
                $dbw = wfGetDB( DB_MASTER );
@@ -259,4 +268,4 @@ class MySQLSearchResultSet extends SearchResultSet {
        function free() {
                $this->mResultSet->free();
        }
-}
+}
\ No newline at end of file