diff options
Diffstat (limited to 'includes/search/SearchPostgres.php')
-rw-r--r-- | includes/search/SearchPostgres.php | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/includes/search/SearchPostgres.php b/includes/search/SearchPostgres.php index 0006fa82..9d6d1539 100644 --- a/includes/search/SearchPostgres.php +++ b/includes/search/SearchPostgres.php @@ -1,23 +1,25 @@ <?php -# Copyright (C) 2006-2007 Greg Sabino Mullane <greg@turnstep.com> -# http://www.mediawiki.org/ -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# http://www.gnu.org/copyleft/gpl.html - /** + * PostgreSQL search engine + * + * Copyright © 2006-2007 Greg Sabino Mullane <greg@turnstep.com> + * http://www.mediawiki.org/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file * @ingroup Search */ @@ -27,9 +29,12 @@ * @ingroup Search */ class SearchPostgres extends SearchEngine { - + /** + * Creates an instance of this class + * @param $db DatabaseSqlite: database object + */ function __construct( $db ) { - $this->db = $db; + parent::__construct( $db ); } /** @@ -129,24 +134,21 @@ class SearchPostgres extends SearchEngine { /** * Construct the full SQL query to do the search. - * @param $filteredTerm String + * @param $term String * @param $fulltext String + * @param $colname */ function searchQuery( $term, $fulltext, $colname ) { - global $wgDBversion; + $postgresVersion = $this->db->getServerVersion(); - if ( !isset( $wgDBversion ) ) { - $this->db->getServerVersion(); - $wgDBversion = $this->db->numeric_version; - } - $prefix = $wgDBversion < 8.3 ? "'default'," : ''; + $prefix = $postgresVersion < 8.3 ? "'default'," : ''; # Get the SQL fragment for the given term $searchstring = $this->parseQuery( $term ); ## We need a separate query here so gin does not complain about empty searches $SQL = "SELECT to_tsquery($prefix $searchstring)"; - $res = $this->db->doQuery($SQL); + $res = $this->db->query($SQL); if (!$res) { ## TODO: Better output (example to catch: one 'two) die ("Sorry, that was not a valid search string. Please go back and try again"); @@ -166,8 +168,8 @@ class SearchPostgres extends SearchEngine { } } - $rankscore = $wgDBversion > 8.2 ? 5 : 1; - $rank = $wgDBversion < 8.3 ? 'rank' : 'ts_rank'; + $rankscore = $postgresVersion > 8.2 ? 5 : 1; + $rank = $postgresVersion < 8.3 ? 'rank' : 'ts_rank'; $query = "SELECT page_id, page_namespace, page_title, ". "$rank($fulltext, to_tsquery($prefix $searchstring), $rankscore) AS score ". "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " . @@ -204,7 +206,7 @@ class SearchPostgres extends SearchEngine { $SQL = "UPDATE pagecontent SET textvector = NULL WHERE old_id IN ". "(SELECT rev_text_id FROM revision WHERE rev_page = " . intval( $pageid ) . " ORDER BY rev_text_id DESC OFFSET 1)"; - $this->db->doQuery($SQL); + $this->db->query($SQL); return true; } |