Increase parity between api search and on-wiki search
authorErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 29 Apr 2015 20:42:03 +0000 (13:42 -0700)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Thu, 30 Apr 2015 15:52:04 +0000 (08:52 -0700)
The on wiki search indicates more information than is currently
available by api.  Adds two more props to improve parity:

* categorysnippet: similar to the other snippets, about the category
  that triggered the match
* isfilematch: indicates if the match was part of file content

Additionally when 'suggestion' is included as part of the searchinfo,
'suggestionsnippet' is now also returned.

Change-Id: Ibf18905775a79caed213aca1bdebcffe3644c23b

includes/api/ApiQuerySearch.php
includes/api/i18n/en.json

index e29ef8d..c12630e 100644 (file)
@@ -129,6 +129,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                        if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) {
                                $apiResult->addValue( array( 'query', 'searchinfo' ),
                                        'suggestion', $matches->getSuggestionQuery() );
+                               $apiResult->addValue( array( 'query', 'searchinfo' ),
+                                       'suggestionsnippet', $matches->getSuggestionSnippet() );
                        }
                }
 
@@ -172,6 +174,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                if ( isset( $prop['titlesnippet'] ) ) {
                                        $vals['titlesnippet'] = $result->getTitleSnippet();
                                }
+                               if ( isset( $prop['categorysnippet'] ) ) {
+                                       $vals['categorysnippet'] = $result->getCategorySnippet();
+                               }
                                if ( !is_null( $result->getRedirectTitle() ) ) {
                                        if ( isset( $prop['redirecttitle'] ) ) {
                                                $vals['redirecttitle'] = $result->getRedirectTitle()->getPrefixedText();
@@ -188,6 +193,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                                $vals['sectionsnippet'] = $result->getSectionSnippet();
                                        }
                                }
+                               if ( isset( $prop['isfilematch'] ) ) {
+                                       $vals['isfilematch'] = $result->isFileMatch();
+                               }
 
                                // Add item to results and see whether it fits
                                $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ),
@@ -314,6 +322,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase {
                                        'sectiontitle',
                                        'sectionsnippet',
                                        'hasrelated',
+                                       'isfilematch',
+                                       'categorysnippet',
                                ),
                                ApiBase::PARAM_ISMULTI => true,
                        ),
index b90664e..bf1fe97 100644 (file)
        "apihelp-query+search-param-namespace": "Search only within these namespaces.",
        "apihelp-query+search-param-what": "Which type of search to perform.",
        "apihelp-query+search-param-info": "Which metadata to return.",
-       "apihelp-query+search-param-prop": "Which properties to return:\n;size:Adds the size of the page in bytes.\n;wordcount:Adds the word count of the page.\n;timestamp:Adds the timestamp of when the page was last edited.\n;snippet:Adds a parsed snippet of the page.\n;titlesnippet:Adds a parsed snippet of the page title.\n;redirectsnippet:Adds a parsed snippet of the redirect title.\n;redirecttitle:Adds the title of the matching redirect.\n;sectionsnippet:Adds a parsed snippet of the matching section title.\n;sectiontitle:Adds the title of the matching section.\n;score:<span class=\"apihelp-deprecated\">Deprecated and ignored.</span>\n;hasrelated:<span class=\"apihelp-deprecated\">Deprecated and ignored.</span>",
+       "apihelp-query+search-param-prop": "Which properties to return:\n;size:Adds the size of the page in bytes.\n;wordcount:Adds the word count of the page.\n;timestamp:Adds the timestamp of when the page was last edited.\n;snippet:Adds a parsed snippet of the page.\n;titlesnippet:Adds a parsed snippet of the page title.\n;redirectsnippet:Adds a parsed snippet of the redirect title.\n;redirecttitle:Adds the title of the matching redirect.\n;sectionsnippet:Adds a parsed snippet of the matching section title.\n;sectiontitle:Adds the title of the matching section.\n;categorysnippet:Adds a parsed snippet of the matching category.\n;isfilematch:Adds a boolean indicating if the search matched file content.\n;score:<span class=\"apihelp-deprecated\">Deprecated and ignored.</span>\n;hasrelated:<span class=\"apihelp-deprecated\">Deprecated and ignored.</span>",
        "apihelp-query+search-param-limit": "How many total pages to return.",
        "apihelp-query+search-param-interwiki": "Include interwiki results in the search, if available.",
        "apihelp-query+search-param-backend": "Which search backend to use, if not the default.",