From 87558fc80b968f1c47978869ac557dde90ad4ea0 Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Wed, 29 Apr 2015 13:42:03 -0700 Subject: [PATCH] Increase parity between api search and on-wiki search 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 | 10 ++++++++++ includes/api/i18n/en.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index e29ef8d2f0..c12630ed80 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -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, ), diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index b90664e040..bf1fe97392 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -871,7 +871,7 @@ "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:Deprecated and ignored.\n;hasrelated:Deprecated and ignored.", + "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:Deprecated and ignored.\n;hasrelated:Deprecated and ignored.", "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.", -- 2.20.1