Fix for bug 13004, in which the Postgres full-text search has too many results,
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Sun, 17 Feb 2008 14:11:55 +0000 (14:11 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Sun, 17 Feb 2008 14:11:55 +0000 (14:11 +0000)
so it throws an error. Created a "too many" class as an alternate search result
to return, and consider any error in SearchPostgres when running the actual search as a "too many"
problem. Not an ideal solution, but I'm not sure how to get at the error message
without requiring a newer version of PHP.

RELEASE-NOTES
includes/SearchEngine.php
includes/SearchPostgres.php
includes/SpecialSearch.php
languages/messages/MessagesEn.php

index 08ca791..a693362 100644 (file)
@@ -395,6 +395,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 12846) IE rtl.css issue in RTL wikis special:Preferences when selecting an
   LTR user language
 * (bug 13005) DISPLAYTITLE does not work on preview
+* (bug 13004) Fix error on Postgres searches that return too many results.
 
 == Parser changes in 1.12 ==
 
index c25b9bd..c22e58d 100644 (file)
@@ -339,10 +339,19 @@ class SearchResultSet {
 }
 
 
+/**
+ * @addtogroup Search
+ */
+class SearchResultTooMany {
+       ## Some search engines may bail out if too many matches are found
+}
+
+
 /**
  * @addtogroup Search
  */
 class SearchResult {
+
        function SearchResult( $row ) {
                $this->mTitle = Title::makeTitle( $row->page_namespace, $row->page_title );
        }
index eb1ac31..59110a5 100644 (file)
@@ -37,11 +37,24 @@ class SearchPostgres extends SearchEngine {
         * @access public
         */
        function searchTitle( $term ) {
-               $resultSet = $this->db->resultObject( $this->db->query( $this->searchQuery( $term , 'titlevector', 'page_title' )));
+               $q = $this->searchQuery( $term , 'titlevector', 'page_title' );
+               $olderror = error_reporting(E_ERROR);
+               $resultSet = $this->db->resultObject( $this->db->query( $q, 'SearchPostgres', true ) );
+               error_reporting($olderror);
+               if (!$resultSet) {
+                       // Needed for "Query requires full scan, GIN doesn't support it"
+                       return new SearchResultTooMany();
+               }
                return new PostgresSearchResultSet( $resultSet, $this->searchTerms );
        }
        function searchText( $term ) {
-               $resultSet = $this->db->resultObject( $this->db->query( $this->searchQuery( $term, 'textvector', 'old_text' )));
+               $q = $this->searchQuery( $term, 'textvector', 'old_text' );
+               $olderror = error_reporting(E_ERROR);
+               $resultSet = $this->db->resultObject( $this->db->query( $q, 'SearchPostgres', true ) );
+               error_reporting($olderror);
+               if (!$resultSet) {
+                       return new SearchResultTooMany();
+               }
                return new PostgresSearchResultSet( $resultSet, $this->searchTerms );
        }
 
index d28cea3..3ef6fab 100644 (file)
@@ -160,6 +160,15 @@ class SpecialSearch {
                $search->setNamespaces( $this->namespaces );
                $search->showRedirects = $this->searchRedirects;
                $titleMatches = $search->searchTitle( $term );
+
+               // Sometimes the search engine knows there are too many hits
+               if ($titleMatches instanceof SearchResultTooMany) {
+                       $wgOut->addWikiText( '==' . wfMsg( 'toomanymatches' ) . "==\n" );
+                       $wgOut->addHTML( $this->powerSearchBox( $term ) );
+                       $wgOut->addHTML( $this->powerSearchFocus() );
+                       wfProfileOut( $fname );
+                       return;
+               }
                $textMatches = $search->searchText( $term );
 
                $num = ( $titleMatches ? $titleMatches->numRows() : 0 )
index ce8d60e..0d3d94b 100644 (file)
@@ -1203,6 +1203,7 @@ Make sure that this change will maintain historical page continuity.
 'searchsubtitleinvalid' => "You searched for '''$1'''",
 'noexactmatch'          => "'''There is no page titled \"\$1\".''' You can [[:\$1|create this page]].",
 'noexactmatch-nocreate' => "'''There is no page titled \"\$1\".'''",
+'toomanymatches'        => 'Too many matches were returned, please try a different query',
 'titlematches'          => 'Page title matches',
 'notitlematches'        => 'No page title matches',
 'textmatches'           => 'Page text matches',