This should be handled internally by SearchEngine implementations.
Bug: T198860
Change-Id: Ifbfd0fcb81fcacf5228bd2ffcac7b80fca872b2a
Depends-On: I7d4ff9498fa1f4ea66835c634b8931f4c29993fb
logic as it should be handled internally by SearchEngine implementations
supporting this feature. SearchEngine implementations should no longer
override this methods.
+* SearchEngine::replacePrefixes( $query ) should no longer be called prior
+ to running searchText/searchTitle.
=== Other changes in 1.32 ===
* (T198811) The following tables have had their UNIQUE indexes turned into
wfDeprecated( 'SearchEngine::transformSearchTerm() (overridden by ' .
get_class( $search ) . ')', '1.32' );
}
- $query = $search->replacePrefixes( $query );
+ $nquery = $search->replacePrefixes( $query );
+ if ( $nquery !== $query ) {
+ $query = $nquery;
+ wfDeprecated( 'SearchEngine::replacePrefixes() (overridden by ' .
+ get_class( $search ) . ')', '1.32' );
+ }
// Perform the actual search
if ( $what == 'text' ) {
$matches = $search->searchText( $query );
* @ingroup Search
* @since 1.23
*/
-class SearchDatabase extends SearchEngine {
+abstract class SearchDatabase extends SearchEngine {
/**
* @var IDatabase Slave database for reading from for results
*/
}
}
+ /**
+ * @param string $term
+ * @return SearchResultSet|Status|null
+ */
+ final public function doSearchText( $term ) {
+ return $this->doSearchTextInDB( $this->extractNamespacePrefix( $term ) );
+ }
+
+ /**
+ * Perform a full text search query and return a result set.
+ *
+ * @param string $term Raw search term
+ * @return SqlSearchResultSet
+ */
+ abstract protected function doSearchTextInDB( $term );
+
+ /**
+ * @param string $term
+ * @return SearchResultSet|null
+ */
+ final public function doSearchTitle( $term ) {
+ return $this->doSearchTitleInDB( $this->extractNamespacePrefix( $term ) );
+ }
+
+ /**
+ * Perform a title-only search query and return a result set.
+ *
+ * @param string $term Raw search term
+ * @return SqlSearchResultSet
+ */
+ abstract protected function doSearchTitleInDB( $term );
+
/**
* Return a 'cleaned up' search string
*
$lc = $this->legalSearchChars( self::CHARS_ALL );
return trim( preg_replace( "/[^{$lc}]/", " ", $text ) );
}
+
+ /**
+ * Extract the optional namespace prefix and set self::namespaces
+ * accordingly and return the query string
+ * @param string $term
+ * @return string the query string without any namespace prefix
+ */
+ final protected function extractNamespacePrefix( $term ) {
+ $queryAndNs = self::parseNamespacePrefixes( $term );
+ if ( $queryAndNs === false ) {
+ return $term;
+ }
+ $this->namespaces = $queryAndNs[1];
+ return $queryAndNs[0];
+ }
}
* or namespace names and set the list of namespaces
* of this class accordingly.
*
+ * @deprecated since 1.32; should be handled internally by the search engine
* @param string $query
* @return string
*/
function replacePrefixes( $query ) {
- $queryAndNs = self::parseNamespacePrefixes( $query );
- if ( $queryAndNs === false ) {
- return $query;
- }
- $this->namespaces = $queryAndNs[1];
- return $queryAndNs[0];
+ return $query;
}
/**
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchText( $term ) {
+ protected function doSearchTextInDB( $term ) {
$resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), true ) );
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchTitle( $term ) {
+ protected function doSearchTitleInDB( $term ) {
$resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), false ) );
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchText( $term ) {
+ protected function doSearchTextInDB( $term ) {
return $this->searchInternal( $term, true );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchTitle( $term ) {
+ protected function doSearchTitleInDB( $term ) {
return $this->searchInternal( $term, false );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchText( $term ) {
+ protected function doSearchTextInDB( $term ) {
if ( $term == '' ) {
return new SqlSearchResultSet( false, '' );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchTitle( $term ) {
+ protected function doSearchTitleInDB( $term ) {
if ( $term == '' ) {
return new SqlSearchResultSet( false, '' );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchTitle( $term ) {
+ protected function doSearchTitleInDB( $term ) {
$q = $this->searchQuery( $term, 'titlevector', 'page_title' );
$olderror = error_reporting( E_ERROR );
$resultSet = $this->db->query( $q, 'SearchPostgres', true );
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
- protected function doSearchText( $term ) {
+ protected function doSearchTextInDB( $term ) {
$q = $this->searchQuery( $term, 'textvector', 'old_text' );
$olderror = error_reporting( E_ERROR );
$resultSet = $this->db->query( $q, 'SearchPostgres', true );
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchText( $term ) {
+ protected function doSearchTextInDB( $term ) {
return $this->searchInternal( $term, true );
}
* @param string $term Raw search term
* @return SqlSearchResultSet
*/
- protected function doSearchTitle( $term ) {
+ protected function doSearchTitleInDB( $term ) {
return $this->searchInternal( $term, false );
}
$showSuggestion = $title === null || !$title->isKnown();
$search->setShowSuggestion( $showSuggestion );
- $nterm = $search->transformSearchTerm( $term );
- if ( $nterm !== $term ) {
- $term = $nterm;
+ $rewritten = $search->transformSearchTerm( $term );
+ if ( $rewritten !== $term ) {
+ $term = $rewritten;
wfDeprecated( 'SearchEngine::transformSearchTerm() (overridden by ' .
get_class( $search ) . ')', '1.32' );
}
- // fetch search results
$rewritten = $search->replacePrefixes( $term );
+ if ( $rewritten !== $term ) {
+ wfDeprecated( 'SearchEngine::replacePrefixes() (overridden by ' .
+ get_class( $search ) . ')', '1.32' );
+ }
+ // fetch search results
$titleMatches = $search->searchTitle( $rewritten );
$textMatches = $search->searchText( $rewritten );