<?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
*/
* @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 );
}
/**
/**
* 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;
-
- if ( !isset( $wgDBversion ) ) {
- $this->db->getServerVersion();
- $wgDBversion = $this->db->numeric_version;
- }
- $prefix = $wgDBversion < 8.3 ? "'default'," : '';
+ $postgresVersion = $this->db->getServerVersion();
# 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)";
+ $SQL = "SELECT to_tsquery($searchstring)";
$res = $this->db->doQuery($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");
}
- $top = pg_fetch_result($res,0,0);
+ $top = $res->fetchRow();
+ $top = $top[0];
if ($top === "") { ## e.g. if only stopwords are used XXX return something better
$query = "SELECT page_id, page_namespace, page_title, 0 AS score ".
}
}
- $rankscore = $wgDBversion > 8.2 ? 5 : 1;
- $rank = $wgDBversion < 8.3 ? 'rank' : 'ts_rank';
$query = "SELECT page_id, page_namespace, page_title, ".
- "$rank($fulltext, to_tsquery($prefix $searchstring), $rankscore) AS score ".
+ "ts_rank($fulltext, to_tsquery($searchstring), 5) 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($prefix $searchstring)";
+ "AND r.rev_text_id = c.old_id AND $fulltext @@ to_tsquery($searchstring)";
}
## Redirects
$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;
}
/**
* @ingroup Search
*/
-class PostgresSearchResultSet extends SearchResultSet {
+class PostgresSearchResultSet extends SqlSearchResultSet {
function __construct( $resultSet, $terms ) {
- $this->mResultSet = $resultSet;
- $this->mTerms = $terms;
- }
-
- function termMatches() {
- return $this->mTerms;
- }
-
- function numRows() {
- return $this->mResultSet->numRows();
+ parent::__construct( $resultSet, $terms );
}
function next() {