diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/search/SearchSqlite.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/search/SearchSqlite.php')
-rw-r--r-- | includes/search/SearchSqlite.php | 116 |
1 files changed, 38 insertions, 78 deletions
diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 554181f6..eee69307 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -25,24 +25,10 @@ * Search engine hook for SQLite * @ingroup Search */ -class SearchSqlite extends SearchEngine { - - /** - * @var DatabaseSqlite - */ - protected $db; - - /** - * Creates an instance of this class - * @param $db DatabaseSqlite: database object - */ - function __construct( $db ) { - parent::__construct( $db ); - } - +class SearchSqlite extends SearchDatabase { /** * Whether fulltext search is supported by current schema - * @return Boolean + * @return bool */ function fulltextSearchSupported() { return $this->db->checkForEnabledSearch(); @@ -52,11 +38,13 @@ class SearchSqlite extends SearchEngine { * Parse the user's query and transform it into an SQL fragment which will * become part of a WHERE clause * + * @param string $filteredText + * @param bool $fulltext * @return string */ function parseQuery( $filteredText, $fulltext ) { global $wgContLang; - $lc = SearchEngine::legalSearchChars(); // Minus format chars + $lc = $this->legalSearchChars(); // Minus format chars $searchon = ''; $this->searchTerms = array(); @@ -64,7 +52,9 @@ class SearchSqlite extends SearchEngine { if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/', $filteredText, $m, PREG_SET_ORDER ) ) { foreach ( $m as $bits ) { - @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; + wfSuppressWarnings(); + list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits; + wfRestoreWarnings(); if ( $nonQuoted != '' ) { $term = $nonQuoted; @@ -127,9 +117,9 @@ class SearchSqlite extends SearchEngine { wfDebug( __METHOD__ . ": Can't understand search query '{$filteredText}'\n" ); } - $searchon = $this->db->strencode( $searchon ); + $searchon = $this->db->addQuotes( $searchon ); $field = $this->getIndexField( $fulltext ); - return " $field MATCH '$searchon' "; + return " $field MATCH $searchon "; } function regexTerm( $string, $wildcard ) { @@ -158,8 +148,8 @@ class SearchSqlite extends SearchEngine { /** * Perform a full text search query and return a result set. * - * @param string $term raw search term - * @return SqliteSearchResultSet + * @param string $term Raw search term + * @return SqlSearchResultSet */ function searchText( $term ) { return $this->searchInternal( $term, true ); @@ -168,15 +158,15 @@ class SearchSqlite extends SearchEngine { /** * Perform a title-only search query and return a result set. * - * @param string $term raw search term - * @return SqliteSearchResultSet + * @param string $term Raw search term + * @return SqlSearchResultSet */ function searchTitle( $term ) { return $this->searchInternal( $term, false ); } protected function searchInternal( $term, $fulltext ) { - global $wgCountTotalSearchHits, $wgContLang; + global $wgContLang; if ( !$this->fulltextSearchSupported() ) { return null; @@ -186,33 +176,19 @@ class SearchSqlite extends SearchEngine { $resultSet = $this->db->query( $this->getQuery( $filteredTerm, $fulltext ) ); $total = null; - if ( $wgCountTotalSearchHits ) { - $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); - $row = $totalResult->fetchObject(); - if ( $row ) { - $total = intval( $row->c ); - } - $totalResult->free(); + $totalResult = $this->db->query( $this->getCountQuery( $filteredTerm, $fulltext ) ); + $row = $totalResult->fetchObject(); + if ( $row ) { + $total = intval( $row->c ); } + $totalResult->free(); - return new SqliteSearchResultSet( $resultSet, $this->searchTerms, $total ); - } - - /** - * Return a partial WHERE clause to exclude redirects, if so set - * @return String - */ - function queryRedirect() { - if ( $this->showRedirects ) { - return ''; - } else { - return 'AND page_is_redirect=0'; - } + return new SqlSearchResultSet( $resultSet, $this->searchTerms, $total ); } /** * Return a partial WHERE clause to limit the search to the given namespaces - * @return String + * @return string */ function queryNamespaces() { if ( is_null( $this->namespaces ) ) { @@ -228,8 +204,8 @@ class SearchSqlite extends SearchEngine { /** * Returns a query with limit for number of results set. - * @param $sql String: - * @return String + * @param string $sql + * @return string */ function limitResult( $sql ) { return $this->db->limitResult( $sql, $this->limit, $this->offset ); @@ -238,22 +214,21 @@ class SearchSqlite extends SearchEngine { /** * Construct the full SQL query to do the search. * The guts shoulds be constructed in queryMain() - * @param $filteredTerm String - * @param $fulltext Boolean - * @return String + * @param string $filteredTerm + * @param bool $fulltext + * @return string */ function getQuery( $filteredTerm, $fulltext ) { return $this->limitResult( $this->queryMain( $filteredTerm, $fulltext ) . ' ' . - $this->queryRedirect() . ' ' . $this->queryNamespaces() ); } /** * Picks which field to index on, depending on what type of query. - * @param $fulltext Boolean - * @return String + * @param bool $fulltext + * @return string */ function getIndexField( $fulltext ) { return $fulltext ? 'si_text' : 'si_title'; @@ -262,9 +237,9 @@ class SearchSqlite extends SearchEngine { /** * Get the base part of the search query. * - * @param $filteredTerm String - * @param $fulltext Boolean - * @return String + * @param string $filteredTerm + * @param bool $fulltext + * @return string */ function queryMain( $filteredTerm, $fulltext ) { $match = $this->parseQuery( $filteredTerm, $fulltext ); @@ -281,8 +256,7 @@ class SearchSqlite extends SearchEngine { $searchindex = $this->db->tableName( 'searchindex' ); return "SELECT COUNT(*) AS c " . "FROM $page,$searchindex " . - "WHERE page_id=$searchindex.rowid AND $match" . - $this->queryRedirect() . ' ' . + "WHERE page_id=$searchindex.rowid AND $match " . $this->queryNamespaces(); } @@ -290,9 +264,9 @@ class SearchSqlite extends SearchEngine { * Create or update the search index record for the given page. * Title and text should be pre-processed. * - * @param $id Integer - * @param $title String - * @param $text String + * @param int $id + * @param string $title + * @param string $text */ function update( $id, $title, $text ) { if ( !$this->fulltextSearchSupported() ) { @@ -316,8 +290,8 @@ class SearchSqlite extends SearchEngine { * Update a search index record's title only. * Title should be pre-processed. * - * @param $id Integer - * @param $title String + * @param int $id + * @param string $title */ function updateTitle( $id, $title ) { if ( !$this->fulltextSearchSupported() ) { @@ -331,17 +305,3 @@ class SearchSqlite extends SearchEngine { __METHOD__ ); } } - -/** - * @ingroup Search - */ -class SqliteSearchResultSet extends SqlSearchResultSet { - function __construct( $resultSet, $terms, $totalHits = null ) { - parent::__construct( $resultSet, $terms ); - $this->mTotalHits = $totalHits; - } - - function getTotalHits() { - return $this->mTotalHits; - } -} |