Smalyshev has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/230162

Change subject: Add option to dump Elasticsearch response
......................................................................

Add option to dump Elasticsearch response

Change-Id: I26ca9a27d05b02118e5c60534c81d5f56df37254
---
M includes/CirrusSearch.php
M includes/Searcher.php
2 files changed, 24 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/62/230162/1

diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index bd07179..9002048 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -97,6 +97,8 @@
                $request = $context->getRequest();
                $dumpQuery = $request && $request->getVal( 'cirrusDumpQuery' ) 
!== null;
                $searcher->setReturnQuery( $dumpQuery );
+               $dumpResult = $request && $request->getVal( 'cirrusDumpResult' 
) !== null;
+               $searcher->setDumpResult( $dumpResult );
                // Delegate to either searchText or moreLikeThisArticle and 
dump the result into $status
                if ( substr( $term, 0, strlen( self::MORE_LIKE_THIS_PREFIX ) ) 
=== self::MORE_LIKE_THIS_PREFIX ) {
                        $term = substr( $term, strlen( 
self::MORE_LIKE_THIS_PREFIX ) );
@@ -132,7 +134,7 @@
                        $searcher->setResultsType( new FullTextResultsType( 
$highlightingConfig ) );
                        $status = $searcher->searchText( $term, 
$this->showSuggestion );
                }
-               if ( $dumpQuery ) {
+               if ( $dumpQuery || $dumpResult ) {
                        // When dumping the query we skip _everything_ but 
echoing the query.
                        $context->getOutput()->disable();
                        $request->response()->header( 'Content-type: 
application/json; charset=UTF-8' );
diff --git a/includes/Searcher.php b/includes/Searcher.php
index df44122..69e0e5b 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -180,6 +180,11 @@
        private $returnQuery = false;
 
        /**
+        * @var boolean return raw Elasticsearch result instead of processing it
+        */
+       private $returnResult = false;
+
+       /**
         * @var null|float[] lazily initialized version of 
$wgCirrusSearchNamespaceWeights with all string keys
         * translated into integer namespace codes using $this->language.
         */
@@ -231,6 +236,13 @@
         */
        public function setReturnQuery( $returnQuery ) {
                $this->returnQuery = $returnQuery;
+       }
+
+       /**
+        * @param boolean $returnQuery just return the array that makes up the 
query instead of searching
+        */
+       public function setDumpResult( $dumpResult ) {
+               $this->returnResult = $dumpResult;
        }
 
        /**
@@ -1204,6 +1216,15 @@
                        });
                if ( $result->isOK() ) {
                        $responseData = 
$result->getValue()->getResponse()->getData();
+
+                       if ( $this->returnResult ) {
+                               return Status::newGood( array(
+                                               'description' => $description,
+                                               'path' => $search->getPath(),
+                                               'result' => $responseData,
+                               ) );
+                       }
+
                        $result->setResult( true, 
$this->resultsType->transformElasticsearchResult( $this->suggestPrefixes,
                                $this->suggestSuffixes, $result->getValue(), 
$this->searchContainedSyntax ) );
                        if ( $responseData[ 'timed_out' ] ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/230162
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I26ca9a27d05b02118e5c60534c81d5f56df37254
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to