From: David Causse Date: Tue, 10 Jul 2018 12:10:09 +0000 (+0200) Subject: Deprecate SearchEngine::replacePrefixes X-Git-Tag: 1.34.0-rc.0~4736 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=cf41c48f8d2292f2774bb3d3b3736166389ddf74;p=lhc%2Fweb%2Fwiklou.git Deprecate SearchEngine::replacePrefixes This should be handled internally by SearchEngine implementations. Bug: T198860 Change-Id: Ifbfd0fcb81fcacf5228bd2ffcac7b80fca872b2a Depends-On: I7d4ff9498fa1f4ea66835c634b8931f4c29993fb --- diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index 4f1cd798c6..c2dbd9d9c1 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -273,6 +273,8 @@ because of Phabricator reports. 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 diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 2153fdc75c..f5461e0ace 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -72,8 +72,13 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { 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 ); diff --git a/includes/search/SearchDatabase.php b/includes/search/SearchDatabase.php index f2929a3b67..93f8d2301f 100644 --- a/includes/search/SearchDatabase.php +++ b/includes/search/SearchDatabase.php @@ -28,7 +28,7 @@ use Wikimedia\Rdbms\IDatabase; * @ingroup Search * @since 1.23 */ -class SearchDatabase extends SearchEngine { +abstract class SearchDatabase extends SearchEngine { /** * @var IDatabase Slave database for reading from for results */ @@ -45,6 +45,38 @@ class SearchDatabase extends SearchEngine { } } + /** + * @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 * @@ -58,4 +90,19 @@ class SearchDatabase extends SearchEngine { $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]; + } } diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index d46918f0ec..30c2271916 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -387,16 +387,12 @@ abstract class SearchEngine { * 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; } /** diff --git a/includes/search/SearchMssql.php b/includes/search/SearchMssql.php index 30ac92da09..289f925f83 100644 --- a/includes/search/SearchMssql.php +++ b/includes/search/SearchMssql.php @@ -34,7 +34,7 @@ class SearchMssql extends SearchDatabase { * @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 ); } @@ -45,7 +45,7 @@ class SearchMssql extends SearchDatabase { * @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 ); } diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index 9a03ebe950..6253b5588e 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -167,7 +167,7 @@ class SearchMySQL extends SearchDatabase { * @param string $term Raw search term * @return SqlSearchResultSet */ - protected function doSearchText( $term ) { + protected function doSearchTextInDB( $term ) { return $this->searchInternal( $term, true ); } @@ -177,7 +177,7 @@ class SearchMySQL extends SearchDatabase { * @param string $term Raw search term * @return SqlSearchResultSet */ - protected function doSearchTitle( $term ) { + protected function doSearchTitleInDB( $term ) { return $this->searchInternal( $term, false ); } diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php index 7fe5b53ca6..6d7e988663 100644 --- a/includes/search/SearchOracle.php +++ b/includes/search/SearchOracle.php @@ -64,7 +64,7 @@ class SearchOracle extends SearchDatabase { * @param string $term Raw search term * @return SqlSearchResultSet */ - protected function doSearchText( $term ) { + protected function doSearchTextInDB( $term ) { if ( $term == '' ) { return new SqlSearchResultSet( false, '' ); } @@ -79,7 +79,7 @@ class SearchOracle extends SearchDatabase { * @param string $term Raw search term * @return SqlSearchResultSet */ - protected function doSearchTitle( $term ) { + protected function doSearchTitleInDB( $term ) { if ( $term == '' ) { return new SqlSearchResultSet( false, '' ); } diff --git a/includes/search/SearchPostgres.php b/includes/search/SearchPostgres.php index 729e528fd6..6d5f1171d5 100644 --- a/includes/search/SearchPostgres.php +++ b/includes/search/SearchPostgres.php @@ -37,7 +37,7 @@ class SearchPostgres extends SearchDatabase { * @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 ); @@ -45,7 +45,7 @@ class SearchPostgres extends SearchDatabase { 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 ); diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 1dc37d2560..0ed477ab2f 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -156,7 +156,7 @@ class SearchSqlite extends SearchDatabase { * @param string $term Raw search term * @return SqlSearchResultSet */ - protected function doSearchText( $term ) { + protected function doSearchTextInDB( $term ) { return $this->searchInternal( $term, true ); } @@ -166,7 +166,7 @@ class SearchSqlite extends SearchDatabase { * @param string $term Raw search term * @return SqlSearchResultSet */ - protected function doSearchTitle( $term ) { + protected function doSearchTitleInDB( $term ) { return $this->searchInternal( $term, false ); } diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 15349b8a41..2cff90e396 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -314,16 +314,20 @@ class SpecialSearch extends SpecialPage { $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 );