EBernhardson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394120 )

Change subject: Include highlight snippets when using search as api generator
......................................................................

Include highlight snippets when using search as api generator

It turned out when using ApiQuerySearch in generator mode important
highlighting information was never returned. This makes it hard to
figure out why a search for intitle:park returned 'Capilano Suspension
Bridge' (because there is a redirect with the word park). Add all
requested gsrprop to the generator result.

Change-Id: Iea48937662492445783104077666ab1f1b30da2d
---
M includes/api/ApiQuerySearch.php
1 file changed, 10 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/20/394120/1

diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index f0c4180..832d84f 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -145,9 +145,11 @@
                // Add the search results to the result
                $terms = $wgContLang->convertForSearchResult( 
$matches->termMatches() );
                $titles = [];
+               $metadata = [];
                $count = 0;
                $result = $matches->next();
                $limit = $params['limit'];
+               $offset = $params['offset'] + 1;
 
                while ( $result ) {
                        if ( ++$count > $limit ) {
@@ -175,6 +177,12 @@
                                }
                        } else {
                                $titles[] = $result->getTitle();
+                               $metadata[] = [
+                                       'title' => $result->getTitle(),
+                                       'data' => $this->getSearchResultData( 
$result, $prop, $terms ) + [
+                                               'index' => $count - 1 + $offset,
+                                       ],
+                               ];
                        }
 
                        $result = $matches->next();
@@ -209,9 +217,8 @@
                                return $current;
                        } );
                        $resultPageSet->populateFromTitles( $titles );
-                       $offset = $params['offset'] + 1;
-                       foreach ( $titles as $index => $title ) {
-                               $resultPageSet->setGeneratorData( $title, [ 
'index' => $index + $offset ] );
+                       foreach ( $metadata as $data ) {
+                               $resultPageSet->setGeneratorData( 
$data['title'], $data['data'] );
                        }
                }
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iea48937662492445783104077666ab1f1b30da2d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to