* (bug 12553) Fixed invalid XHTML in edit conflict screen
[lhc/web/wiklou.git] / includes / SearchPostgres.php
index daebfa7..cf9e698 100644 (file)
@@ -21,7 +21,6 @@
  * Search engine hook base class for Postgres
  * @addtogroup Search
  */
-
 class SearchPostgres extends SearchEngine {
 
        function SearchPostgres( $db ) {
@@ -64,9 +63,8 @@ class SearchPostgres extends SearchEngine {
                ## Treat colons as word separators:
                $term = preg_replace('/:/', ' ', $term);
 
-               $this->searchTerms = array();
-               $m = array();
                $searchstring = '';
+               $m = array();
                if( preg_match_all('/([-!]?)(\S+)\s*/', $term, $m, PREG_SET_ORDER ) ) {
                        foreach( $m as $terms ) {
                                if (strlen($terms[1])) {
@@ -83,8 +81,6 @@ class SearchPostgres extends SearchEngine {
                                }
                                else {
                                        $searchstring .= " & $terms[2]";
-                                       $safeterm = preg_replace('/\W+/', '', $terms[2]);
-                                       $this->searchTerms[$safeterm] = $safeterm;
                                }
                        }
                }
@@ -98,8 +94,11 @@ class SearchPostgres extends SearchEngine {
                ## Remove any non-spaced operators (e.g. "Zounds!")
                $searchstring = preg_replace('/([^ ])[\!\&\|]/', "$1", $searchstring);
 
-               ## Remove any trailing operators
-               $searchstring = preg_replace('/(?: [\!\&\|])*$/', '', $searchstring);
+               ## Remove any trailing whitespace or operators
+               $searchstring = preg_replace('/[\s\!\&\|]+$/', '', $searchstring);
+
+               ## Remove unnecessary quotes around everything
+               $searchstring = preg_replace('/^[\'"](.*)[\'"]$/', "$1", $searchstring);
 
                ## Quote the whole thing
                $searchstring = $this->db->addQuotes($searchstring);
@@ -117,6 +116,12 @@ class SearchPostgres extends SearchEngine {
         * @private
         */
        function searchQuery( $term, $fulltext, $colname ) {
+               global $wgDBversion;
+
+               if ( !isset( $wgDBversion ) ) {
+                       $this->db->getServerVersion();
+                       $wgDBversion = $this->db->numeric_version;
+               }
 
                $searchstring = $this->parseQuery( $term );
 
@@ -135,8 +140,16 @@ class SearchPostgres extends SearchEngine {
                                "AND r.rev_text_id = c.old_id AND 1=0";
                }
                else {
+                       $m = array();
+                       if( preg_match_all("/'([^']+)'/", $top, $m, PREG_SET_ORDER ) ) {
+                               foreach( $m as $terms ) {
+                                       $this->searchTerms[$terms[1]] = $terms[1];
+                               }
+                       }
+
+                       $rankscore = $wgDBversion > 8.2 ? 5 : 1;
                        $query = "SELECT page_id, page_namespace, page_title, ".
-                       "rank($fulltext, to_tsquery('default',$searchstring),5) AS score ".
+                       "rank($fulltext, to_tsquery('default',$searchstring), $rankscore) AS score ".
                        "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " .
                        "AND r.rev_text_id = c.old_id AND $fulltext @@ to_tsquery('default',$searchstring)";
                }
@@ -179,7 +192,9 @@ class SearchPostgres extends SearchEngine {
 
 } ## end of the SearchPostgres class
 
-
+/**
+ * @addtogroup Search
+ */
 class PostgresSearchResult extends SearchResult {
        function PostgresSearchResult( $row ) {
                $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title );
@@ -190,6 +205,9 @@ class PostgresSearchResult extends SearchResult {
        }
 }
 
+/**
+ * @addtogroup Search
+ */
 class PostgresSearchResultSet extends SearchResultSet {
        function PostgresSearchResultSet( $resultSet, $terms ) {
                $this->mResultSet = $resultSet;
@@ -215,4 +233,4 @@ class PostgresSearchResultSet extends SearchResultSet {
 }
 
 
-?>
+