106 return 'AND page_namespace IN (' .
$namespaces .
')';
117 return $this->db->limitResult( $sql, $this->limit, $this->offset );
129 return ' ORDER BY score(1)';
139 private function getQuery( $filteredTerm, $fulltext ) {
142 $this->
queryRanking( $filteredTerm, $fulltext ) .
' ' );
151 return $fulltext ?
'si_text' :
'si_title';
162 $match = $this->
parseQuery( $filteredTerm, $fulltext );
163 $page = $this->db->tableName(
'page' );
164 $searchindex = $this->db->tableName(
'searchindex' );
165 return 'SELECT page_id, page_namespace, page_title ' .
166 "FROM $page,$searchindex " .
167 'WHERE page_id=si_page AND ' . $match;
179 $this->searchTerms = [];
181 # @todo FIXME: This doesn't handle parenthetical expressions.
184 if ( preg_match_all(
'/([-+<>~]?)(([' . $lc .
']+)(\*?)|"[^"]*")/',
185 $filteredText, $m, PREG_SET_ORDER ) ) {
186 foreach ( $m
as $terms ) {
189 $temp_terms = MediaWikiServices::getInstance()->getContentLanguage()->
190 autoConvertToAllVariants( $terms[2] );
191 if ( is_array( $temp_terms ) ) {
192 $temp_terms = array_unique( array_values( $temp_terms ) );
193 foreach ( $temp_terms
as $t ) {
194 $searchon .= ( $terms[1] ==
'-' ?
' ~' :
' & ' ) . $this->
escapeTerm( $t );
197 $searchon .= ( $terms[1] ==
'-' ?
' ~' :
' & ' ) . $this->
escapeTerm( $terms[2] );
199 if ( !empty( $terms[3] ) ) {
200 $regexp = preg_quote( $terms[3],
'/' );
202 $regexp .=
"[0-9A-Za-z_]+";
205 $regexp = preg_quote( str_replace(
'"',
'', $terms[2] ),
'/' );
207 $this->searchTerms[] = $regexp;
211 $searchon = $this->db->addQuotes( ltrim( $searchon,
' &' ) );
213 return " CONTAINS($field, $searchon, 1) > 0 ";
217 $t = MediaWikiServices::getInstance()->getContentLanguage()->normalizeForSearch(
$t );
218 $t = isset( $this->reservedWords[strtoupper(
$t )] ) ?
'{' .
$t .
'}' :
$t;
219 $t = preg_replace(
'/^"(.*)"$/',
'($1)',
$t );
220 $t = preg_replace(
'/([-&|])/',
'\\\\$1',
$t );
234 $dbw->replace(
'searchindex',
240 ],
'SearchOracle::update' );
247 $dbw->query(
"CALL ctx_ddl.sync_index(" .
248 $dbw->addQuotes( $dbw->getDBname() .
'.' . $dbw->tableName(
'si_text_idx',
'raw' ) ) .
")" );
249 $dbw->query(
"CALL ctx_ddl.sync_index(" .
250 $dbw->addQuotes( $dbw->getDBname() .
'.' . $dbw->tableName(
'si_title_idx',
'raw' ) ) .
")" );
263 $dbw->update(
'searchindex',
265 [
'si_page' => $id ],
266 'SearchOracle::updateTitle',
271 $searchChars = parent::legalSearchChars(
$type );
272 if (
$type === self::CHARS_ALL ) {
273 $searchChars =
"\"" . $searchChars;