* 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 = $this->legalSearchChars(); // Minus format chars
$searchon = '';
- $this->searchTerms = array();
+ $this->searchTerms = [];
- $m = array();
+ $m = [];
if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
$filteredText, $m, PREG_SET_ORDER ) ) {
foreach ( $m as $bits ) {
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
- wfRestoreWarnings();
+ MediaWiki\restoreWarnings();
if ( $nonQuoted != '' ) {
$term = $nonQuoted;
if ( is_array( $convertedVariants ) ) {
$variants = array_unique( array_values( $convertedVariants ) );
} else {
- $variants = array( $term );
+ $variants = [ $term ];
}
// The low-level search index does some processing on input to work
// fulltext engine.
// For Chinese this also inserts spaces between adjacent Han characters.
$strippedVariants = array_map(
- array( $wgContLang, 'normalizeForSearch' ),
+ [ $wgContLang, 'normalizeForSearch' ],
$variants );
// Some languages such as Chinese force all variants to a canonical
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 ) {
}
protected function searchInternal( $term, $fulltext ) {
- global $wgCountTotalSearchHits, $wgContLang;
+ global $wgContLang;
if ( !$this->fulltextSearchSupported() ) {
return null;
$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 SqlSearchResultSet( $resultSet, $this->searchTerms, $total );
}
// couldn't do it so far due to typelessness of FTS3 tables.
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'searchindex', array( 'rowid' => $id ), __METHOD__ );
+ $dbw->delete( 'searchindex', [ 'rowid' => $id ], __METHOD__ );
$dbw->insert( 'searchindex',
- array(
+ [
'rowid' => $id,
'si_title' => $title,
'si_text' => $text
- ), __METHOD__ );
+ ], __METHOD__ );
}
/**
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'searchindex',
- array( 'si_title' => $title ),
- array( 'rowid' => $id ),
+ [ 'si_title' => $title ],
+ [ 'rowid' => $id ],
__METHOD__ );
}
}