Brion VIBBER has uploaded a new change for review.

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

Change subject: Work in progress: add extensible metadata to search results & 
API
......................................................................

Work in progress: add extensible metadata to search results & API

* Adds getMetadata() on SearchResult base class
** currently includes the non-default existing fields as examples
** also includes the newest Cirrus-specific fields, will want to migrate those
* If srprop=metadata passed to list=search, this array gets included if 
non-empty
** appears as <metadata> subelement of <p> in XML
** appears as 'metadata':{} key in JSON

Change-Id: I88ee54b52dbd320d8f6a9cc4ae3fd7ed634a7d50
---
M includes/api/ApiQuerySearch.php
M includes/search/SearchResult.php
2 files changed, 46 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/27/152727/1

diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php
index 5ed5873..90131a7 100644
--- a/includes/api/ApiQuerySearch.php
+++ b/includes/api/ApiQuerySearch.php
@@ -179,6 +179,9 @@
                                if ( isset( $prop['hasrelated'] ) && 
$result->hasRelated() ) {
                                        $vals['hasrelated'] = '';
                                }
+                               if ( isset( $prop['metadata'] ) && 
$result->getMetadata() ) {
+                                       $vals['metadata'] = 
$result->getMetadata();
+                               }
 
                                // Add item to results and see whether it fits
                                $fit = $apiResult->addValue( array( 'query', 
$this->getModuleName() ),
@@ -294,6 +297,7 @@
                                        'sectiontitle',
                                        'sectionsnippet',
                                        'hasrelated',
+                                       'metadata',
                                ),
                                ApiBase::PARAM_ISMULTI => true,
                        ),
diff --git a/includes/search/SearchResult.php b/includes/search/SearchResult.php
index d51bff7..7d41a96 100644
--- a/includes/search/SearchResult.php
+++ b/includes/search/SearchResult.php
@@ -265,4 +265,46 @@
        function isFileMatch() {
                return false;
        }
+
+       /**
+        * Get additional metadata fields, totally extensible by the engine.
+        * Exposed to API search query only when asking for 'srprop=metadata'
+        *
+        * Recommend using key => string pairs, keep it simple!
+        *
+        * @return array
+        */
+       function getMetadata() {
+               // Old fields that aren't in the default set
+               // Not sure if we want to keep these? But good to demo with.
+               $metadata = array();
+               if ( $this->getTitleSnippet() !== '') {
+                       $metadata['titleSnippet'] = $this->getTitleSnippet();
+               }
+               if ( $this->getRedirectTitle() != '' ) {
+                       $metadata['redirectTitle'] = $this->getRedirectTitle();
+               }
+               if ( $this->getRedirectSnippet() != '' ) {
+                       $metadata['redirectSnippet'] = 
$this->getRedirectSnippet();
+               }
+               if ( $this->getSectionTitle() !== null ) {
+                       $metadata['sectionTitle'] = 
$this->getSectionTitle()->getFragment();
+               }
+               if ( $this->getSectionSnippet() != '') {
+                       $metadata['sectionSnippet'] = 
$this->getSectionSnippet();
+               }
+               if ( $this->hasRelated() ) {
+                       $metadata['sectionSnippet'] = '';
+               }
+
+               // New fields, definitely want these going in here
+               // Probably will kill the old getters/setters
+               if ( $this->isFileMatch() ) {
+                       $metadata['isFileMatch'] = '';
+               }
+               if ( $this->getInterwikiNamespaceText() !== '' ) {
+                       $metadata['interwikiNamespaceText'] = 
$this->getInterwikiNamespaceText();
+               }
+               return $metadata;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I88ee54b52dbd320d8f6a9cc4ae3fd7ed634a7d50
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brion VIBBER <br...@wikimedia.org>

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

Reply via email to