summaryrefslogtreecommitdiff
path: root/includes/search
diff options
context:
space:
mode:
Diffstat (limited to 'includes/search')
-rw-r--r--includes/search/SearchEngine.php83
-rw-r--r--includes/search/SearchIBM_DB2.php234
-rw-r--r--includes/search/SearchMssql.php19
-rw-r--r--includes/search/SearchMySQL.php8
-rw-r--r--includes/search/SearchOracle.php142
-rw-r--r--includes/search/SearchPostgres.php44
-rw-r--r--includes/search/SearchSqlite.php15
-rw-r--r--includes/search/SearchUpdate.php13
8 files changed, 164 insertions, 394 deletions
diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index 27a321ac..6b3e62b1 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -45,7 +45,7 @@ class SearchEngine {
*/
protected $db;
- function __construct($db = null) {
+ function __construct( $db = null ) {
if ( $db ) {
$this->db = $db;
} else {
@@ -58,7 +58,7 @@ class SearchEngine {
* If title searches are not supported or disabled, return null.
* STUB
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return SearchResultSet
*/
function searchText( $term ) {
@@ -70,7 +70,7 @@ class SearchEngine {
* If title searches are not supported or disabled, return null.
* STUB
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return SearchResultSet
*/
function searchTitle( $term ) {
@@ -118,7 +118,7 @@ class SearchEngine {
* on text to be used for searching or updating search index.
* Default implementation does nothing (simply returns $string).
*
- * @param $string string: String to process
+ * @param string $string String to process
* @return string
*/
public function normalizeText( $string ) {
@@ -163,7 +163,7 @@ class SearchEngine {
/**
* Really find the title match.
- * @return null|\Title
+ * @return null|Title
*/
private static function getNearMatchInternal( $searchterm ) {
global $wgContLang, $wgEnableSearchContributorsByIP;
@@ -183,10 +183,15 @@ class SearchEngine {
# Exact match? No need to look further.
$title = Title::newFromText( $term );
- if ( is_null( $title ) ){
+ if ( is_null( $title ) ) {
return null;
}
+ # Try files if searching in the Media: namespace
+ if ( $title->getNamespace() == NS_MEDIA ) {
+ $title = Title::makeTitle( NS_FILE, $title->getText() );
+ }
+
if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
return $title;
}
@@ -197,22 +202,23 @@ class SearchEngine {
return $title;
}
+ if ( !wfRunHooks( 'SearchAfterNoDirectMatch', array( $term, &$title ) ) ) {
+ return $title;
+ }
+
# Now try all lower case (i.e. first letter capitalized)
- #
$title = Title::newFromText( $wgContLang->lc( $term ) );
if ( $title && $title->exists() ) {
return $title;
}
# Now try capitalized string
- #
$title = Title::newFromText( $wgContLang->ucwords( $term ) );
if ( $title && $title->exists() ) {
return $title;
}
# Now try all upper case
- #
$title = Title::newFromText( $wgContLang->uc( $term ) );
if ( $title && $title->exists() ) {
return $title;
@@ -233,7 +239,6 @@ class SearchEngine {
$title = Title::newFromText( $searchterm );
-
# Entering an IP address goes to the contributions page
if ( $wgEnableSearchContributorsByIP ) {
if ( ( $title->getNamespace() == NS_USER && User::isIP( $title->getText() ) )
@@ -242,7 +247,6 @@ class SearchEngine {
}
}
-
# Entering a user goes to the user page whether it's there or not
if ( $title->getNamespace() == NS_USER ) {
return $title;
@@ -669,7 +673,6 @@ class SearchResultTooMany {
# # Some search engines may bail out if too many matches are found
}
-
/**
* @todo FIXME: This class is horribly factored. It would probably be better to
* have a useful base class to which you pass some standard information, then
@@ -791,21 +794,26 @@ class SearchResult {
*/
protected function initText() {
if ( !isset( $this->mText ) ) {
- if ( $this->mRevision != null )
- $this->mText = $this->mRevision->getText();
- else // TODO: can we fetch raw wikitext for commons images?
+ if ( $this->mRevision != null ) {
+ //TODO: if we could plug in some code that knows about special content models *and* about
+ // special features of the search engine, the search could benefit.
+ $content = $this->mRevision->getContent();
+ $this->mText = $content ? $content->getTextForSearchIndex() : '';
+ } else { // TODO: can we fetch raw wikitext for commons images?
$this->mText = '';
-
+ }
}
}
/**
- * @param $terms Array: terms to highlight
+ * @param array $terms terms to highlight
* @return String: highlighted text snippet, null (and not '') if not supported
*/
function getTextSnippet( $terms ) {
global $wgUser, $wgAdvancedSearchHighlighting;
$this->initText();
+
+ // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs( $wgUser );
$h = new SearchHighlighter();
if ( $wgAdvancedSearchHighlighting )
@@ -815,7 +823,7 @@ class SearchResult {
}
/**
- * @param $terms Array: terms to highlight
+ * @param array $terms terms to highlight
* @return String: highlighted title, '' if not supported
*/
function getTitleSnippet( $terms ) {
@@ -823,7 +831,7 @@ class SearchResult {
}
/**
- * @param $terms Array: terms to highlight
+ * @param array $terms terms to highlight
* @return String: highlighted redirect name (redirect to this page), '' if none or not supported
*/
function getRedirectSnippet( $terms ) {
@@ -934,7 +942,7 @@ class SearchHighlighter {
* Default implementation of wikitext highlighting
*
* @param $text String
- * @param $terms Array: terms to highlight (unescaped)
+ * @param array $terms terms to highlight (unescaped)
* @param $contextlines Integer
* @param $contextchars Integer
* @return String
@@ -962,7 +970,7 @@ class SearchHighlighter {
}
$spat .= '/';
$textExt = array(); // text extracts
- $otherExt = array(); // other extracts
+ $otherExt = array(); // other extracts
wfProfileIn( "$fname-split" );
$start = 0;
$textLen = strlen( $text );
@@ -1131,8 +1139,8 @@ class SearchHighlighter {
// add more lines
$add = $index + 1;
while ( $len < $targetchars - 20
- && array_key_exists( $add, $all )
- && !array_key_exists( $add, $snippets ) ) {
+ && array_key_exists( $add, $all )
+ && !array_key_exists( $add, $snippets ) ) {
$offsets[$add] = 0;
$tt = "\n" . $this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] );
$extended[$add] = $tt;
@@ -1142,7 +1150,7 @@ class SearchHighlighter {
}
}
- // $snippets = array_map('htmlspecialchars', $extended);
+ // $snippets = array_map( 'htmlspecialchars', $extended );
$snippets = $extended;
$last = - 1;
$extract = '';
@@ -1177,7 +1185,7 @@ class SearchHighlighter {
/**
* Split text into lines and add it to extracts array
*
- * @param $extracts Array: index -> $line
+ * @param array $extracts index -> $line
* @param $count Integer
* @param $text String
*/
@@ -1232,7 +1240,7 @@ class SearchHighlighter {
$posEnd = $end;
}
- if ( $end > $start ) {
+ if ( $end > $start ) {
return substr( $text, $start, $end - $start );
} else {
return '';
@@ -1272,12 +1280,12 @@ class SearchHighlighter {
/**
* Search extracts for a pattern, and return snippets
*
- * @param $pattern String: regexp for matching lines
- * @param $extracts Array: extracts to search
+ * @param string $pattern regexp for matching lines
+ * @param array $extracts extracts to search
* @param $linesleft Integer: number of extracts to make
* @param $contextchars Integer: length of snippet
- * @param $out Array: map for highlighted snippets
- * @param $offsets Array: map of starting points of snippets
+ * @param array $out map for highlighted snippets
+ * @param array $offsets map of starting points of snippets
* @protected
*/
function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
@@ -1321,12 +1329,12 @@ class SearchHighlighter {
$fname = __METHOD__;
wfProfileIn( $fname );
- // $text = preg_replace("/'{2,5}/", "", $text);
- // $text = preg_replace("/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text);
- // $text = preg_replace("/\[\[([^]|]+)\]\]/", "\\1", $text);
- // $text = preg_replace("/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text);
- // $text = preg_replace("/\\{\\|(.*?)\\|\\}/", "", $text);
- // $text = preg_replace("/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text);
+ // $text = preg_replace( "/'{2,5}/", "", $text );
+ // $text = preg_replace( "/\[[a-z]+:\/\/[^ ]+ ([^]]+)\]/", "\\2", $text );
+ // $text = preg_replace( "/\[\[([^]|]+)\]\]/", "\\1", $text );
+ // $text = preg_replace( "/\[\[([^]]+\|)?([^|]]+)\]\]/", "\\2", $text );
+ // $text = preg_replace( "/\\{\\|(.*?)\\|\\}/", "", $text );
+ // $text = preg_replace( "/\\[\\[[A-Za-z_-]+:([^|]+?)\\]\\]/", "", $text );
$text = preg_replace( "/\\{\\{([^|]+?)\\}\\}/", "", $text );
$text = preg_replace( "/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text );
$text = preg_replace( "/\\[\\[([^|]+?)\\]\\]/", "\\1", $text );
@@ -1408,8 +1416,7 @@ class SearchHighlighter {
$line = htmlspecialchars( $pre . $found . $post );
$pat2 = '/(' . $terms . ")/i";
- $line = preg_replace( $pat2,
- "<span class='searchmatch'>\\1</span>", $line );
+ $line = preg_replace( $pat2, "<span class='searchmatch'>\\1</span>", $line );
$extract .= "${line}\n";
}
diff --git a/includes/search/SearchIBM_DB2.php b/includes/search/SearchIBM_DB2.php
deleted file mode 100644
index 51ed000f..00000000
--- a/includes/search/SearchIBM_DB2.php
+++ /dev/null
@@ -1,234 +0,0 @@
-<?php
-/**
- * IBM DB2 search engine
- *
- * Copyright © 2004 Brion Vibber <brion@pobox.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
- */
-
-/**
- * Search engine hook base class for IBM DB2
- * @ingroup Search
- */
-class SearchIBM_DB2 extends SearchEngine {
-
- /**
- * Creates an instance of this class
- * @param $db DatabaseIbm_db2: database object
- */
- function __construct($db) {
- parent::__construct( $db );
- }
-
- /**
- * Perform a full text search query and return a result set.
- *
- * @param $term String: raw search term
- * @return SqlSearchResultSet
- */
- function searchText( $term ) {
- $resultSet = $this->db->resultObject($this->db->query($this->getQuery($this->filter($term), true)));
- return new SqlSearchResultSet($resultSet, $this->searchTerms);
- }
-
- /**
- * Perform a title-only search query and return a result set.
- *
- * @param $term String: taw search term
- * @return SqlSearchResultSet
- */
- function searchTitle($term) {
- $resultSet = $this->db->resultObject($this->db->query($this->getQuery($this->filter($term), false)));
- return new SqlSearchResultSet($resultSet, $this->searchTerms);
- }
-
-
- /**
- * 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 a partial WHERE clause to limit the search to the given namespaces
- * @return String
- */
- function queryNamespaces() {
- if( is_null($this->namespaces) )
- return '';
- $namespaces = implode(',', $this->namespaces);
- if ($namespaces == '') {
- $namespaces = '0';
- }
- return 'AND page_namespace IN (' . $namespaces . ')';
- }
-
- /**
- * Return a LIMIT clause to limit results on the query.
- * @return String
- */
- function queryLimit( $sql ) {
- return $this->db->limitResult($sql, $this->limit, $this->offset);
- }
-
- /**
- * Does not do anything for generic search engine
- * subclasses may define this though
- * @return String
- */
- function queryRanking($filteredTerm, $fulltext) {
- // requires Net Search Extender or equivalent
- // return ' ORDER BY score(1)';
- return '';
- }
-
- /**
- * Construct the full SQL query to do the search.
- * The guts shoulds be constructed in queryMain()
- * @param $filteredTerm String
- * @param $fulltext Boolean
- * @return String
- */
- function getQuery( $filteredTerm, $fulltext ) {
- return $this->queryLimit($this->queryMain($filteredTerm, $fulltext) . ' ' .
- $this->queryRedirect() . ' ' .
- $this->queryNamespaces() . ' ' .
- $this->queryRanking( $filteredTerm, $fulltext ) . ' ');
- }
-
-
- /**
- * Picks which field to index on, depending on what type of query.
- * @param $fulltext Boolean
- * @return String
- */
- function getIndexField($fulltext) {
- return $fulltext ? 'si_text' : 'si_title';
- }
-
- /**
- * Get the base part of the search query.
- *
- * @param $filteredTerm String
- * @param $fulltext Boolean
- * @return String
- */
- function queryMain( $filteredTerm, $fulltext ) {
- $match = $this->parseQuery($filteredTerm, $fulltext);
- $page = $this->db->tableName('page');
- $searchindex = $this->db->tableName('searchindex');
- return 'SELECT page_id, page_namespace, page_title ' .
- "FROM $page,$searchindex " .
- 'WHERE page_id=si_page AND ' . $match;
- }
-
- /** @todo document
- * @return string
- */
- function parseQuery($filteredText, $fulltext) {
- global $wgContLang;
- $lc = SearchEngine::legalSearchChars();
- $this->searchTerms = array();
-
- # @todo FIXME: This doesn't handle parenthetical expressions.
- $m = array();
- $q = array();
-
- if (preg_match_all('/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
- $filteredText, $m, PREG_SET_ORDER)) {
- foreach($m as $terms) {
-
- // Search terms in all variant forms, only
- // apply on wiki with LanguageConverter
- $temp_terms = $wgContLang->autoConvertToAllVariants( $terms[2] );
- if( is_array( $temp_terms )) {
- $temp_terms = array_unique( array_values( $temp_terms ));
- foreach( $temp_terms as $t )
- $q[] = $terms[1] . $wgContLang->normalizeForSearch( $t );
- }
- else
- $q[] = $terms[1] . $wgContLang->normalizeForSearch( $terms[2] );
-
- if (!empty($terms[3])) {
- $regexp = preg_quote( $terms[3], '/' );
- if ($terms[4])
- $regexp .= "[0-9A-Za-z_]+";
- } else {
- $regexp = preg_quote(str_replace('"', '', $terms[2]), '/');
- }
- $this->searchTerms[] = $regexp;
- }
- }
-
- $searchon = $this->db->strencode(join(',', $q));
- $field = $this->getIndexField($fulltext);
-
- // requires Net Search Extender or equivalent
- //return " CONTAINS($field, '$searchon') > 0 ";
-
- return " lcase($field) LIKE lcase('%$searchon%')";
- }
-
- /**
- * 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
- */
- function update($id, $title, $text) {
- $dbw = wfGetDB(DB_MASTER);
- $dbw->replace('searchindex',
- array('si_page'),
- array(
- 'si_page' => $id,
- 'si_title' => $title,
- 'si_text' => $text
- ), 'SearchIBM_DB2::update' );
- // ?
- //$dbw->query("CALL ctx_ddl.sync_index('si_text_idx')");
- //$dbw->query("CALL ctx_ddl.sync_index('si_title_idx')");
- }
-
- /**
- * Update a search index record's title only.
- * Title should be pre-processed.
- *
- * @param $id Integer
- * @param $title String
- */
- function updateTitle($id, $title) {
- $dbw = wfGetDB(DB_MASTER);
-
- $dbw->update('searchindex',
- array('si_title' => $title),
- array('si_page' => $id),
- 'SearchIBM_DB2::updateTitle',
- array());
- }
-}
diff --git a/includes/search/SearchMssql.php b/includes/search/SearchMssql.php
index 69c92ba3..163d9dc3 100644
--- a/includes/search/SearchMssql.php
+++ b/includes/search/SearchMssql.php
@@ -38,7 +38,7 @@ class SearchMssql extends SearchEngine {
/**
* Perform a full text search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return MssqlSearchResultSet
* @access public
*/
@@ -50,7 +50,7 @@ class SearchMssql extends SearchEngine {
/**
* Perform a title-only search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return MssqlSearchResultSet
* @access public
*/
@@ -59,7 +59,6 @@ class SearchMssql extends SearchEngine {
return new MssqlSearchResultSet( $resultSet, $this->searchTerms );
}
-
/**
* Return a partial WHERE clause to exclude redirects, if so set
*
@@ -78,7 +77,7 @@ class SearchMssql extends SearchEngine {
* Return a partial WHERE clause to limit the search to the given namespaces
*
* @return String
- * @private
+ * @private
*/
function queryNamespaces() {
$namespaces = implode( ',', $this->namespaces );
@@ -144,9 +143,9 @@ class SearchMssql extends SearchEngine {
*/
function queryMain( $filteredTerm, $fulltext ) {
$match = $this->parseQuery( $filteredTerm, $fulltext );
- $page = $this->db->tableName( 'page' );
+ $page = $this->db->tableName( 'page' );
$searchindex = $this->db->tableName( 'searchindex' );
-
+
return 'SELECT page_id, page_namespace, page_title, ftindex.[RANK]' .
"FROM $page,FREETEXTTABLE($searchindex , $match, LANGUAGE 'English') as ftindex " .
'WHERE page_id=ftindex.[KEY] ';
@@ -192,11 +191,11 @@ class SearchMssql extends SearchEngine {
* @param $id Integer
* @param $title String
* @param $text String
- * @return bool|\ResultWrapper
+ * @return bool|ResultWrapper
*/
function update( $id, $title, $text ) {
// We store the column data as UTF-8 byte order marked binary stream
- // because we are invoking the plain text IFilter on it so that, and we want it
+ // because we are invoking the plain text IFilter on it so that, and we want it
// to properly decode the stream as UTF-8. SQL doesn't support UTF8 as a data type
// but the indexer will correctly handle it by this method. Since all we are doing
// is passing this data to the indexer and never retrieving it via PHP, this will save space
@@ -215,7 +214,7 @@ class SearchMssql extends SearchEngine {
*
* @param $id Integer
* @param $title String
- * @return bool|\ResultWrapper
+ * @return bool|ResultWrapper
*/
function updateTitle( $id, $title ) {
$table = $this->db->tableName( 'searchindex' );
@@ -253,5 +252,3 @@ class MssqlSearchResultSet extends SearchResultSet {
return new SearchResult( $row );
}
}
-
-
diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php
index 5cee03e0..4a501fd0 100644
--- a/includes/search/SearchMySQL.php
+++ b/includes/search/SearchMySQL.php
@@ -58,7 +58,7 @@ class SearchMySQL extends SearchEngine {
# @todo FIXME: This doesn't handle parenthetical expressions.
$m = array();
if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
- $filteredText, $m, PREG_SET_ORDER ) ) {
+ $filteredText, $m, PREG_SET_ORDER ) ) {
foreach( $m as $bits ) {
@list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
@@ -156,7 +156,7 @@ class SearchMySQL extends SearchEngine {
/**
* Perform a full text search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return MySQLSearchResultSet
*/
function searchText( $term ) {
@@ -166,7 +166,7 @@ class SearchMySQL extends SearchEngine {
/**
* Perform a title-only search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return MySQLSearchResultSet
*/
function searchTitle( $term ) {
@@ -221,7 +221,7 @@ class SearchMySQL extends SearchEngine {
*/
protected function queryFeatures( &$query ) {
foreach ( $this->features as $feature => $value ) {
- if ( $feature === 'list-redirects' && !$value ) {
+ if ( $feature === 'list-redirects' && !$value ) {
$query['conds']['page_is_redirect'] = 0;
} elseif( $feature === 'title-suffix-filter' && $value ) {
$query['conds'][] = 'page_title' . $this->db->buildLike( $this->db->anyString(), $value );
diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php
index a2db52f3..b0ea97fe 100644
--- a/includes/search/SearchOracle.php
+++ b/includes/search/SearchOracle.php
@@ -29,77 +29,76 @@
* @ingroup Search
*/
class SearchOracle extends SearchEngine {
-
- private $reservedWords = array ('ABOUT' => 1,
- 'ACCUM' => 1,
- 'AND' => 1,
- 'BT' => 1,
- 'BTG' => 1,
- 'BTI' => 1,
+
+ private $reservedWords = array ('ABOUT' => 1,
+ 'ACCUM' => 1,
+ 'AND' => 1,
+ 'BT' => 1,
+ 'BTG' => 1,
+ 'BTI' => 1,
'BTP' => 1,
- 'FUZZY' => 1,
- 'HASPATH' => 1,
- 'INPATH' => 1,
- 'MINUS' => 1,
- 'NEAR' => 1,
+ 'FUZZY' => 1,
+ 'HASPATH' => 1,
+ 'INPATH' => 1,
+ 'MINUS' => 1,
+ 'NEAR' => 1,
'NOT' => 1,
- 'NT' => 1,
- 'NTG' => 1,
- 'NTI' => 1,
- 'NTP' => 1,
- 'OR' => 1,
- 'PT' => 1,
- 'RT' => 1,
+ 'NT' => 1,
+ 'NTG' => 1,
+ 'NTI' => 1,
+ 'NTP' => 1,
+ 'OR' => 1,
+ 'PT' => 1,
+ 'RT' => 1,
'SQE' => 1,
- 'SYN' => 1,
- 'TR' => 1,
- 'TRSYN' => 1,
- 'TT' => 1,
+ 'SYN' => 1,
+ 'TR' => 1,
+ 'TRSYN' => 1,
+ 'TT' => 1,
'WITHIN' => 1);
/**
* Creates an instance of this class
* @param $db DatabasePostgres: database object
*/
- function __construct($db) {
+ function __construct( $db ) {
parent::__construct( $db );
}
/**
* Perform a full text search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return SqlSearchResultSet
*/
function searchText( $term ) {
- if ($term == '')
- return new SqlSearchResultSet(false, '');
+ if ( $term == '' )
+ return new SqlSearchResultSet( false, '' );
- $resultSet = $this->db->resultObject($this->db->query($this->getQuery($this->filter($term), true)));
- return new SqlSearchResultSet($resultSet, $this->searchTerms);
+ $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
+ return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
/**
* Perform a title-only search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return SqlSearchResultSet
*/
- function searchTitle($term) {
- if ($term == '')
- return new SqlSearchResultSet(false, '');
+ function searchTitle( $term ) {
+ if ( $term == '' )
+ return new SqlSearchResultSet( false, '' );
- $resultSet = $this->db->resultObject($this->db->query($this->getQuery($this->filter($term), false)));
- return new MySQLSearchResultSet($resultSet, $this->searchTerms);
+ $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
+ return new MySQLSearchResultSet( $resultSet, $this->searchTerms );
}
-
/**
* Return a partial WHERE clause to exclude redirects, if so set
* @return String
*/
function queryRedirect() {
- if ($this->showRedirects) {
+ if ( $this->showRedirects ) {
return '';
} else {
return 'AND page_is_redirect=0';
@@ -111,7 +110,7 @@ class SearchOracle extends SearchEngine {
* @return String
*/
function queryNamespaces() {
- if( is_null($this->namespaces) )
+ if( is_null( $this->namespaces ) )
return '';
if ( !count( $this->namespaces ) ) {
$namespaces = '0';
@@ -129,7 +128,7 @@ class SearchOracle extends SearchEngine {
* @return String
*/
function queryLimit( $sql ) {
- return $this->db->limitResult($sql, $this->limit, $this->offset);
+ return $this->db->limitResult( $sql, $this->limit, $this->offset );
}
/**
@@ -150,19 +149,18 @@ class SearchOracle extends SearchEngine {
* @return String
*/
function getQuery( $filteredTerm, $fulltext ) {
- return $this->queryLimit($this->queryMain($filteredTerm, $fulltext) . ' ' .
+ return $this->queryLimit( $this->queryMain( $filteredTerm, $fulltext ) . ' ' .
$this->queryRedirect() . ' ' .
$this->queryNamespaces() . ' ' .
- $this->queryRanking( $filteredTerm, $fulltext ) . ' ');
+ $this->queryRanking( $filteredTerm, $fulltext ) . ' ' );
}
-
/**
* Picks which field to index on, depending on what type of query.
* @param $fulltext Boolean
* @return String
*/
- function getIndexField($fulltext) {
+ function getIndexField( $fulltext ) {
return $fulltext ? 'si_text' : 'si_title';
}
@@ -174,9 +172,9 @@ class SearchOracle extends SearchEngine {
* @return String
*/
function queryMain( $filteredTerm, $fulltext ) {
- $match = $this->parseQuery($filteredTerm, $fulltext);
- $page = $this->db->tableName('page');
- $searchindex = $this->db->tableName('searchindex');
+ $match = $this->parseQuery( $filteredTerm, $fulltext );
+ $page = $this->db->tableName( 'page' );
+ $searchindex = $this->db->tableName( 'searchindex' );
return 'SELECT page_id, page_namespace, page_title ' .
"FROM $page,$searchindex " .
'WHERE page_id=si_page AND ' . $match;
@@ -187,7 +185,7 @@ class SearchOracle extends SearchEngine {
* as part of a WHERE clause
* @return string
*/
- function parseQuery($filteredText, $fulltext) {
+ function parseQuery( $filteredText, $fulltext ) {
global $wgContLang;
$lc = SearchEngine::legalSearchChars();
$this->searchTerms = array();
@@ -195,9 +193,9 @@ class SearchOracle extends SearchEngine {
# @todo FIXME: This doesn't handle parenthetical expressions.
$m = array();
$searchon = '';
- if (preg_match_all('/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
- $filteredText, $m, PREG_SET_ORDER)) {
- foreach($m as $terms) {
+ if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
+ $filteredText, $m, PREG_SET_ORDER ) ) {
+ foreach( $m as $terms ) {
// Search terms in all variant forms, only
// apply on wiki with LanguageConverter
$temp_terms = $wgContLang->autoConvertToAllVariants( $terms[2] );
@@ -210,27 +208,26 @@ class SearchOracle extends SearchEngine {
else {
$searchon .= ($terms[1] == '-' ? ' ~' : ' & ') . $this->escapeTerm( $terms[2] );
}
- if (!empty($terms[3])) {
+ if ( !empty( $terms[3] ) ) {
$regexp = preg_quote( $terms[3], '/' );
- if ($terms[4])
+ if ( $terms[4] )
$regexp .= "[0-9A-Za-z_]+";
} else {
- $regexp = preg_quote(str_replace('"', '', $terms[2]), '/');
+ $regexp = preg_quote( str_replace( '"', '', $terms[2] ), '/' );
}
$this->searchTerms[] = $regexp;
}
}
-
- $searchon = $this->db->addQuotes(ltrim($searchon, ' &'));
- $field = $this->getIndexField($fulltext);
+ $searchon = $this->db->addQuotes( ltrim( $searchon, ' &' ) );
+ $field = $this->getIndexField( $fulltext );
return " CONTAINS($field, $searchon, 1) > 0 ";
}
- private function escapeTerm($t) {
+ private function escapeTerm( $t ) {
global $wgContLang;
- $t = $wgContLang->normalizeForSearch($t);
- $t = isset($this->reservedWords[strtoupper($t)]) ? '{'.$t.'}' : $t;
+ $t = $wgContLang->normalizeForSearch( $t );
+ $t = isset( $this->reservedWords[strtoupper( $t )] ) ? '{'.$t.'}' : $t;
$t = preg_replace('/^"(.*)"$/', '($1)', $t);
$t = preg_replace('/([-&|])/', '\\\\$1', $t);
return $t;
@@ -243,10 +240,10 @@ class SearchOracle extends SearchEngine {
* @param $title String
* @param $text String
*/
- function update($id, $title, $text) {
- $dbw = wfGetDB(DB_MASTER);
- $dbw->replace('searchindex',
- array('si_page'),
+ function update( $id, $title, $text ) {
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->replace( 'searchindex',
+ array( 'si_page' ),
array(
'si_page' => $id,
'si_title' => $title,
@@ -254,13 +251,13 @@ class SearchOracle extends SearchEngine {
), 'SearchOracle::update' );
// Sync the index
- // We need to specify the DB name (i.e. user/schema) here so that
+ // We need to specify the DB name (i.e. user/schema) here so that
// it can work from the installer, where
// ALTER SESSION SET CURRENT_SCHEMA = ...
// was used.
- $dbw->query( "CALL ctx_ddl.sync_index(" .
+ $dbw->query( "CALL ctx_ddl.sync_index(" .
$dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_text_idx', 'raw' ) ) . ")" );
- $dbw->query( "CALL ctx_ddl.sync_index(" .
+ $dbw->query( "CALL ctx_ddl.sync_index(" .
$dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_title_idx', 'raw' ) ) . ")" );
}
@@ -271,17 +268,16 @@ class SearchOracle extends SearchEngine {
* @param $id Integer
* @param $title String
*/
- function updateTitle($id, $title) {
- $dbw = wfGetDB(DB_MASTER);
+ function updateTitle( $id, $title ) {
+ $dbw = wfGetDB( DB_MASTER );
- $dbw->update('searchindex',
- array('si_title' => $title),
- array('si_page' => $id),
+ $dbw->update( 'searchindex',
+ array( 'si_title' => $title ),
+ array( 'si_page' => $id ),
'SearchOracle::updateTitle',
- array());
+ array() );
}
-
public static function legalSearchChars() {
return "\"" . parent::legalSearchChars();
}
diff --git a/includes/search/SearchPostgres.php b/includes/search/SearchPostgres.php
index 68648894..56464e98 100644
--- a/includes/search/SearchPostgres.php
+++ b/includes/search/SearchPostgres.php
@@ -47,15 +47,15 @@ class SearchPostgres extends SearchEngine {
* Currently searches a page's current title (page.page_title) and
* latest revision article text (pagecontent.old_text)
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return PostgresSearchResultSet
*/
function searchTitle( $term ) {
- $q = $this->searchQuery( $term , 'titlevector', 'page_title' );
- $olderror = error_reporting(E_ERROR);
+ $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) {
+ error_reporting( $olderror );
+ if ( !$resultSet ) {
// Needed for "Query requires full scan, GIN doesn't support it"
return new SearchResultTooMany();
}
@@ -66,8 +66,8 @@ class SearchPostgres extends SearchEngine {
$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) {
+ error_reporting( $olderror );
+ if ( !$resultSet ) {
return new SearchResultTooMany();
}
return new PostgresSearchResultSet( $resultSet, $this->searchTerms );
@@ -99,16 +99,16 @@ class SearchPostgres extends SearchEngine {
$m = array();
if( preg_match_all('/([-!]?)(\S+)\s*/', $term, $m, PREG_SET_ORDER ) ) {
foreach( $m as $terms ) {
- if (strlen($terms[1])) {
+ if ( strlen( $terms[1] ) ) {
$searchstring .= ' & !';
}
- if (strtolower($terms[2]) === 'and') {
+ if ( strtolower( $terms[2] ) === 'and' ) {
$searchstring .= ' & ';
}
- elseif (strtolower($terms[2]) === 'or' or $terms[2] === '|') {
+ elseif ( strtolower( $terms[2] ) === 'or' or $terms[2] === '|' ) {
$searchstring .= ' | ';
}
- elseif (strtolower($terms[2]) === 'not') {
+ elseif ( strtolower( $terms[2] ) === 'not' ) {
$searchstring .= ' & !';
}
else {
@@ -133,7 +133,7 @@ class SearchPostgres extends SearchEngine {
$searchstring = preg_replace('/^[\'"](.*)[\'"]$/', "$1", $searchstring);
## Quote the whole thing
- $searchstring = $this->db->addQuotes($searchstring);
+ $searchstring = $this->db->addQuotes( $searchstring );
wfDebug( "parseQuery returned: $searchstring \n" );
@@ -154,15 +154,15 @@ class SearchPostgres extends SearchEngine {
## We need a separate query here so gin does not complain about empty searches
$SQL = "SELECT to_tsquery($searchstring)";
- $res = $this->db->query($SQL);
- if (!$res) {
+ $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");
+ die( "Sorry, that was not a valid search string. Please go back and try again" );
}
$top = $res->fetchRow();
$top = $top[0];
- if ($top === "") { ## e.g. if only stopwords are used XXX return something better
+ if ( $top === "" ) { ## e.g. if only stopwords are used XXX return something better
$query = "SELECT page_id, page_namespace, page_title, 0 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 1=0";
@@ -182,14 +182,14 @@ class SearchPostgres extends SearchEngine {
}
## Redirects
- if (! $this->showRedirects)
+ if ( !$this->showRedirects )
$query .= ' AND page_is_redirect = 0';
## Namespaces - defaults to 0
- if( !is_null($this->namespaces) ){ // null -> search all
- if ( count($this->namespaces) < 1)
+ if( !is_null( $this->namespaces ) ) { // null -> search all
+ if ( count( $this->namespaces ) < 1 ) {
$query .= ' AND page_namespace = 0';
- else {
+ } else {
$namespaces = $this->db->makeList( $this->namespaces );
$query .= " AND page_namespace IN ($namespaces)";
}
@@ -211,7 +211,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->query($SQL);
+ $this->db->query( $SQL );
return true;
}
@@ -226,7 +226,7 @@ class SearchPostgres extends SearchEngine {
*/
class PostgresSearchResult extends SearchResult {
function __construct( $row ) {
- parent::__construct($row);
+ parent::__construct( $row );
$this->score = $row->score;
}
function getScore() {
diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php
index e52e4fe3..f3f4788c 100644
--- a/includes/search/SearchSqlite.php
+++ b/includes/search/SearchSqlite.php
@@ -62,7 +62,7 @@ class SearchSqlite extends SearchEngine {
$m = array();
if( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
- $filteredText, $m, PREG_SET_ORDER ) ) {
+ $filteredText, $m, PREG_SET_ORDER ) ) {
foreach( $m as $bits ) {
@list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
@@ -156,7 +156,7 @@ class SearchSqlite extends SearchEngine {
/**
* Perform a full text search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return SqliteSearchResultSet
*/
function searchText( $term ) {
@@ -166,7 +166,7 @@ class SearchSqlite extends SearchEngine {
/**
* Perform a title-only search query and return a result set.
*
- * @param $term String: raw search term
+ * @param string $term raw search term
* @return SqliteSearchResultSet
*/
function searchTitle( $term ) {
@@ -196,7 +196,6 @@ class SearchSqlite extends SearchEngine {
return new SqliteSearchResultSet( $resultSet, $this->searchTerms, $total );
}
-
/**
* Return a partial WHERE clause to exclude redirects, if so set
* @return String
@@ -214,7 +213,7 @@ class SearchSqlite extends SearchEngine {
* @return String
*/
function queryNamespaces() {
- if( is_null($this->namespaces) )
+ if( is_null( $this->namespaces ) )
return ''; # search all
if ( !count( $this->namespaces ) ) {
$namespaces = '0';
@@ -266,7 +265,7 @@ class SearchSqlite extends SearchEngine {
*/
function queryMain( $filteredTerm, $fulltext ) {
$match = $this->parseQuery( $filteredTerm, $fulltext );
- $page = $this->db->tableName( 'page' );
+ $page = $this->db->tableName( 'page' );
$searchindex = $this->db->tableName( 'searchindex' );
return "SELECT $searchindex.rowid, page_namespace, page_title " .
"FROM $page,$searchindex " .
@@ -275,7 +274,7 @@ class SearchSqlite extends SearchEngine {
function getCountQuery( $filteredTerm, $fulltext ) {
$match = $this->parseQuery( $filteredTerm, $fulltext );
- $page = $this->db->tableName( 'page' );
+ $page = $this->db->tableName( 'page' );
$searchindex = $this->db->tableName( 'searchindex' );
return "SELECT COUNT(*) AS c " .
"FROM $page,$searchindex " .
@@ -317,7 +316,7 @@ class SearchSqlite extends SearchEngine {
* @param $id Integer
* @param $title String
*/
- function updateTitle( $id, $title ) {
+ function updateTitle( $id, $title ) {
if ( !$this->fulltextSearchSupported() ) {
return;
}
diff --git a/includes/search/SearchUpdate.php b/includes/search/SearchUpdate.php
index 40dd36c2..eabcda3e 100644
--- a/includes/search/SearchUpdate.php
+++ b/includes/search/SearchUpdate.php
@@ -34,7 +34,12 @@ class SearchUpdate implements DeferrableUpdate {
private $mTitleWords;
function __construct( $id, $title, $text = false ) {
- $nt = Title::newFromText( $title );
+ if ( is_string( $title ) ) {
+ $nt = Title::newFromText( $title );
+ } else {
+ $nt = $title;
+ }
+
if( $nt ) {
$this->mId = $id;
$this->mText = $text;
@@ -74,7 +79,7 @@ class SearchUpdate implements DeferrableUpdate {
$text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/",
' ', $wgContLang->lc( " " . $text . " " ) ); # Strip HTML markup
$text = preg_replace( "/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
- "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
+ "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
# Strip external URLs
$uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\x80-\\xFF";
@@ -92,7 +97,7 @@ class SearchUpdate implements DeferrableUpdate {
$text = preg_replace( $pat2, " \\1 \\3", $text );
$text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
- "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
+ "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
# Strip all remaining non-search characters
$text = preg_replace( "/[^{$lc}]+/", " ", $text );
@@ -122,7 +127,7 @@ class SearchUpdate implements DeferrableUpdate {
wfRunHooks( 'SearchUpdate', array( $this->mId, $this->mNamespace, $this->mTitle, &$text ) );
# Perform the actual update
- $search->update($this->mId, $search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) ),
+ $search->update( $this->mId, $search->normalizeText( Title::indexTitle( $this->mNamespace, $this->mTitle ) ),
$search->normalizeText( $text ) );
wfProfileOut( __METHOD__ );