check that $wgArticle is an instance of the Article class in Skin::pageStats() per...
[lhc/web/wiklou.git] / includes / SearchMySQL.php
index f3a7e16..5fc0679 100644 (file)
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 # http://www.gnu.org/copyleft/gpl.html
 
+/**
+ * @file
+ * @ingroup Search
+ */
+
 /**
  * Search engine hook for MySQL 4+
- * @addtogroup Search
+ * @ingroup Search
  */
 class SearchMySQL extends SearchEngine {
        var $strictMatching = true;
@@ -29,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
@@ -49,15 +57,19 @@ class SearchMySQL extends SearchEngine {
                                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] ), '/' );
                                }
-                               $this->searchTerms[] = "\b$regexp\b";
+                               $this->searchTerms[] = $regexp;
                        }
                        wfDebug( "Would search with '$searchon'\n" );
-                       wfDebug( 'Match with /\b' . implode( '\b|\b', $this->searchTerms ) . "\b/\n" );
+                       wfDebug( 'Match with /' . implode( '|', $this->searchTerms ) . "/\n" );
                } else {
                        wfDebug( "Can't understand search query '{$filteredText}'\n" );
                }
@@ -117,9 +129,10 @@ class SearchMySQL extends SearchEngine {
        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 . ')';
        }
@@ -226,7 +239,7 @@ class SearchMySQL extends SearchEngine {
 }
 
 /**
- * @addtogroup Search
+ * @ingroup Search
  */
 class MySQLSearchResultSet extends SearchResultSet {
        function MySQLSearchResultSet( $resultSet, $terms ) {