check that $wgArticle is an instance of the Article class in Skin::pageStats() per...
[lhc/web/wiklou.git] / includes / SearchMySQL.php
index 6f2b338..5fc0679 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
@@ -43,24 +46,22 @@ class SearchMySQL extends SearchEngine {
 
                # FIXME: This doesn't handle parenthetical expressions.
                $m = array();
-               if( preg_match_all( '/([-+<>?~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', 
-                       $filteredText, $m, PREG_SET_ORDER ) )
-               {
+               if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
+                         $filteredText, $m, PREG_SET_ORDER ) ) {
                        foreach( $m as $terms ) {
                                if( $searchon !== '' ) $searchon .= ' ';
-                               if( $this->strictMatching ) {
-                                       // '' means AND while ? means OR to the user
-                                       if( $terms[1] == '' ) {
-                                               $terms[1] = '+';
-                                       } else if( $terms[1] == '?' ) {
-                                               $terms[1] = '';
-                                       }
+                               if( $this->strictMatching && ($terms[1] == '') ) {
+                                       $terms[1] = '+';
                                }
                                $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] ), '/' );
@@ -128,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 . ')';
        }