Ram has uploaded a new change for review.
https://gerrit.wikimedia.org/r/57350
Change subject: Bug: 43544: Propagate lucene errors back to user
......................................................................
Bug: 43544: Propagate lucene errors back to user
When lsearchd responds with 500 errors, we propagate that back to the user.
Bug: 43544
Change-Id: Idb42d64987164ba099228b154729c9c86af7407f
---
M MWSearch_body.php
1 file changed, 33 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MWSearch
refs/changes/50/57350/1
diff --git a/MWSearch_body.php b/MWSearch_body.php
index 7a2642e..acdd56a 100644
--- a/MWSearch_body.php
+++ b/MWSearch_body.php
@@ -470,7 +470,7 @@
// Search server will be in local network but may not trigger
checks on
// Http::isLocal(), so suppress usage of $wgHTTPProxy if
enabled.
- $httpOpts = array( 'proxy' => false );
+ $httpOpts = array( 'proxy' => false, 'timeout' => 'default',
'method' => 'GET' );
wfDebug( "Fetching search data from $searchUrl\n" );
@@ -481,18 +481,32 @@
wfSuppressWarnings();
$httpProfile ="LuceneSearchSet::newFromQuery" .
'-contact-' . $host;
wfProfileIn( $httpProfile );
- $data = Http::get( $searchUrl,
$wgLuceneSearchTimeout, $httpOpts );
+ // $data = Http::get( $searchUrl,
$wgLuceneSearchTimeout, $httpOpts );
+
+ $req = MWHttpRequest::factory( $searchUrl,
$httpOpts );
+ $status = $req->execute();
+
wfProfileOut( $httpProfile );
wfRestoreWarnings();
- return $data;
+ if ( $status->isOK() ) {
+ return array( true, $req->getContent()
);
+ } else {
+ return array( false,
$status->getWikiText() );
+ }
} ) );
$data = $work->execute();
- if( $data === false ) {
+ if( $data[ 0 ] === false ) {
// Network error or server error
+ $errMsg = trim( $data[ 1 ] );
+ if ( "" == $errMsg ) { // should never happen
+ $errMsg = "Internal server error";
+ }
+ $resultSet = new LuceneSearchSet( $method, $query,
$errMsg );
+ wfDebug( "Error -- " . $errMsg . "; returning error
result set\n" );
wfProfileOut( __METHOD__ );
- return null;
+ return $resultSet;
} else {
- $inputLines = explode( "\n", trim( $data ) );
+ $inputLines = explode( "\n", trim( $data[ 1 ] ) );
$resultLines = array_map( 'trim', $inputLines );
}
@@ -525,7 +539,9 @@
while(!self::startsWith($resultLines[$interwikiLen],"#results"))
$interwikiLen++;
$interwikiLines =
array_splice($resultLines,0,$interwikiLen);
- $interwiki = new LuceneSearchSet(
$method, $query, $interwikiLines, intval($iwCount), intval($iwTotal) );
+
+ // errMsg = null
+ $interwiki = new LuceneSearchSet(
$method, $query, null, $interwikiLines, intval($iwCount), intval($iwTotal) );
}
# how many results we got
@@ -536,8 +552,8 @@
}
}
-
- $resultSet = new LuceneSearchSet( $method, $query,
$resultLines, $resultCount, $totalHits,
+ // errMsg = null
+ $resultSet = new LuceneSearchSet( $method, $query, null,
$resultLines, $resultCount, $totalHits,
$suggestion, $info, $interwiki );
if($wgLuceneSearchCacheExpiry > 0){
@@ -558,16 +574,19 @@
*
* @param string $method
* @param string $query
+ * @param string $errMsg
* @param array $lines
* @param int $resultCount
* @param int $totalHits
* @param string $suggestion
* @param string $info
+ * @param string $interwiki
* @access private
*/
- function __construct( $method, $query, $lines, $resultCount, $totalHits
= null, $suggestion = null, $info = null, $interwiki = null ) {
+ function __construct( $method, $query, $errMsg = null, $lines = null,
$resultCount = 0, $totalHits = null, $suggestion = null, $info = null,
$interwiki = null ) {
$this->mMethod = $method;
$this->mQuery = $query;
+ $this->mErrMsg = $errMsg;
$this->mTotalHits = $totalHits;
$this->mResults = $lines;
$this->mResultCount = $resultCount;
@@ -620,6 +639,10 @@
return $this->mResultCount;
}
+ function errMsg() {
+ return $this->mErrMsg;
+ }
+
function termMatches() {
$resq = preg_replace( "/\\[.*?\\]:/", " ", $this->mQuery ); #
generic prefixes
$resq = preg_replace( "/all:/", " ", $resq );
--
To view, visit https://gerrit.wikimedia.org/r/57350
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb42d64987164ba099228b154729c9c86af7407f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MWSearch
Gerrit-Branch: master
Gerrit-Owner: Ram <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits