r53904 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53903‎ | r53904 | r53905 >
Date:21:13, 28 July 2009
Author:brion
Status:ok
Tags:
Comment:
* Added fields to list=search output: size, wordcount, timestamp, snippet
* Where supported by backend, list=search adds a 'searchinfo' element with
optional info: 'totalhits' count and 'suggestion' alternate query term

Snippets added to result items earlier by Roan; extended this with the other
byte size, word count, and timestamp available on the result items and exposed
through the regular UI.

Had to work out a backwards-compatible method for the search meta-information
with Roan; added a second 'searchinfo' element since adding attributes to
'search' would break compatibility for JSON output (despite being safe in XML).

'searchinfo' is present only if the backend supports the extra info and has
something available; 'totalhits' with a total hit count and 'suggestion' for
an alternate query suggestion (exposed as "Did you mean X?" link in UI).

Note that total hit counts can be enabled for MySQL backend now by setting
the experimental option $wgSearchMySQLTotalHits, but did-you-mean suggestions
are not yet supported and need to be tested with a hack or another backend.

Sample XML and JSON output with the new searchinfo items (which can be
present whether or not there are any result items):

<?xml version="1.0"?>
<api>
<query>
<searchinfo totalhits="0" suggestion="joe momma" />
<search />
</query>
</api>

{
"query": {
"searchinfo": {
"totalhits": 0,
"suggestion": "joe momma"
},
"search": [

]
}
}

The suggestion value is suitable for plugging back in as a search term,
if present.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySearch.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuerySearch.php
@@ -86,6 +86,15 @@
8787 if (is_null($matches))
8888 $this->dieUsage("{$what} search is disabled",
8989 "search-{$what}-disabled");
 90+
 91+ $totalhits = $matches->getTotalHits();
 92+ if( $totalhits !== null ) {
 93+ $this->getResult()->addValue( array( 'query', 'searchinfo' ), 'totalhits', $totalhits );
 94+ }
 95+ if( $matches->hasSuggestion() ) {
 96+ $this->getResult()->addValue( array( 'query', 'searchinfo' ), 'suggestion',
 97+ $matches->getSuggestionQuery() );
 98+ }
9099
91100 $terms = $wgContLang->convertForSearchResult($matches->termMatches());
92101 $titles = array ();
@@ -106,6 +115,9 @@
107116 $vals = array();
108117 ApiQueryBase::addTitleInfo($vals, $title);
109118 $vals['snippet'] = $result->getTextSnippet($terms);
 119+ $vals['size'] = $result->getByteSize();
 120+ $vals['wordcount'] = $result->getWordCount();
 121+ $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $result->getTimestamp() );
110122 $fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals);
111123 if(!$fit)
112124 {
Index: trunk/phase3/RELEASE-NOTES
@@ -384,7 +384,6 @@
385385 * (bug 18720) Add anchor field to action=parse&prop=sections output
386386 * (bug 19423) The initial file description page used caption in user lang
387387 rather than UI lang
388 -* Added snippet field to list=search output
389388 * (bug 17809) Add number of users in user groups to meta=siteinfo
390389 * (bug 18533) Add readonly reason to readonly exception
391390 * (bug 19528) Added XSLT parameter to API queries in format=xml
@@ -392,6 +391,9 @@
393392 parameter in action=edit
394393 * (bug 19090) Added watchlist parameter, deprecated watch and unwatch
395394 parameter in action=edit
 395+* Added fields to list=search output: size, wordcount, timestamp, snippet
 396+* Where supported by backend, list=search adds a 'searchinfo' element with
 397+ optional info: 'totalhits' count and 'suggestion' alternate query term
396398
397399 === Languages updated in 1.16 ===
398400

Follow-up revisions

RevisionCommit summaryAuthorDate
r53905Merge r52854, r53904 to deployment -- API search enhancementsbrion21:30, 28 July 2009

Status & tagging log