EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/227578
Change subject: Move query rewriting into search backend
......................................................................
Move query rewriting into search backend
This is the CirrusSearch half of I0a8f75759. In that patch rewriting
was adjusted so it can be implemented directly by the search engine.
This will allow us to make more indepth changes to the way the second
query is run, rather than only having control over the text of the
search.
Bug: T106888
Change-Id: Iebce6a59931ae0c295e13ccc12a22a1ae2081777
---
M includes/CirrusSearch.php
M includes/Search/ResultSet.php
2 files changed, 58 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/78/227578/1
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index 5730852..f3c5b53 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -62,6 +62,46 @@
* @return Search\ResultSet|null|Status results, no results, or error
respectively
*/
public function searchText( $term ) {
+ $matches = $this->searchTextReal( $term );
+ if (!$matches instanceof CirrusSearch\Search\ResultSet) {
+ return $matches;
+ }
+ if (
+ !$this->isFeatureEnabled( 'disableRewrites' )() &&
+ $matches->numRows() === 0 &&
+ !$matches->searchContainedSyntax()
+ ) {
+ $matches = $this->searchTextSecondTry( $matches );
+ }
+ return $matches;
+ }
+
+ private function isFeatureEnabled( $feature ) {
+ return isset( $this->features[$feature] ) &&
$this->features[$feature];
+ }
+
+ private function searchTextSecondTry( CirrusSearch\Search\ResultSet
$zeroResult ) {
+ if ( $zeroResult->hasSuggestion() ) {
+ $rewritten = $zeroResult->getSuggestionQuery();
+ $rewrittenSnippet = $zeroResult->getSuggestionSnippet();
+ } else {
+ // Don't have any other options yet.
+ return $zeroResult;
+ }
+
+ $rewrittenResult = $this->searchTextReal( $rewritten );
+ if (
+ $rewrittenResult instanceof
CirrusSearch\Search\ResultSet
+ && $rewrittenResult->numRows() > 0
+ ) {
+ $rewrittenResult->setRewrittenQuery( $rewritten,
$rewrittenSnippet );
+ return $rewrittenResult;
+ } else {
+ return $zeroResult;
+ }
+ }
+
+ private function searchTextReal( $term ) {
global $wgCirrusSearchInterwikiSources;
// Convert the unicode character 'idiographic whitespace' into
standard
diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php
index 40dcef2..d6e050f 100644
--- a/includes/Search/ResultSet.php
+++ b/includes/Search/ResultSet.php
@@ -27,6 +27,7 @@
private $result, $hits, $totalHits, $suggestionQuery,
$suggestionSnippet;
private $searchContainedSyntax;
private $interwikiPrefix, $interwikiResults;
+ private $rewrittenQuery;
public function __construct( $suggestPrefixes, $suggestSuffixes, $res,
$searchContainedSyntax, $interwiki = '' ) {
$this->result = $res;
@@ -164,4 +165,21 @@
public function searchContainedSyntax() {
return $this->searchContainedSyntax;
}
+
+ public function setRewrittenQuery($newQuery, $newQuerySnippet=null) {
+ $this->rewrittenQuery = $newQuery;
+ $this->rewrittenQuerySnippet = $newQuerySnippet ?:
htmlspecialchars( $newQuery );
+ }
+
+ public function hasRewrittenQuery() {
+ return $this->rewrittenQuery !== null;
+ }
+
+ public function getQueryAfterRewrite() {
+ return $this->rewrittenQuery;
+ }
+
+ public function getQueryAfterRewriteSnippet() {
+ return $this->rewrittenQuerySnippet;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/227578
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebce6a59931ae0c295e13ccc12a22a1ae2081777
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits