* @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( 'ApiQueryBase.php' );
-}
-
/**
* Query module to perform full text search within wiki titles and content
*
$this->run( $resultPageSet );
}
+ /**
+ * @param $resultPageSet ApiPageSet
+ * @return void
+ */
private function run( $resultPageSet = null ) {
global $wgContLang;
$params = $this->extractRequestParams();
$search->setNamespaces( $params['namespace'] );
$search->showRedirects = $params['redirects'];
+ $query = $search->transformSearchTerm( $query );
+ $query = $search->replacePrefixes( $query );
+
// Perform the actual search
if ( $what == 'text' ) {
$matches = $search->searchText( $query );
$this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" );
}
+ $apiResult = $this->getResult();
// Add search meta data to result
if ( isset( $searchInfo['totalhits'] ) ) {
$totalhits = $matches->getTotalHits();
if ( $totalhits !== null ) {
- $this->getResult()->addValue( array( 'query', 'searchinfo' ),
+ $apiResult->addValue( array( 'query', 'searchinfo' ),
'totalhits', $totalhits );
}
}
if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) {
- $this->getResult()->addValue( array( 'query', 'searchinfo' ),
+ $apiResult->addValue( array( 'query', 'searchinfo' ),
'suggestion', $matches->getSuggestionQuery() );
}
$terms = $wgContLang->convertForSearchResult( $matches->termMatches() );
$titles = array();
$count = 0;
- while ( $result = $matches->next() ) {
+ $result = $matches->next();
+
+ while ( $result ) {
if ( ++ $count > $limit ) {
// We've reached the one extra which shows that there are additional items to be had. Stop here...
$this->setContinueEnumParameter( 'offset', $params['offset'] + $params['limit'] );
// Silently skip broken and missing titles
if ( $result->isBrokenTitle() || $result->isMissingRevision() ) {
+ $result = $matches->next();
continue;
}
}
if ( !is_null( $result->getSectionTitle() ) ) {
if ( isset( $prop['sectiontitle'] ) ) {
- $vals['sectiontitle'] = $result->getSectionTitle();
+ $vals['sectiontitle'] = $result->getSectionTitle()->getFragment();
}
if ( isset( $prop['sectionsnippet'] ) ) {
$vals['sectionsnippet'] = $result->getSectionSnippet();
}
// Add item to results and see whether it fits
- $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ),
+ $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ),
null, $vals );
if ( !$fit ) {
$this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 );
} else {
$titles[] = $title;
}
+
+ $result = $matches->next();
}
if ( is_null( $resultPageSet ) ) {
- $this->getResult()->setIndexedTagName_internal( array(
+ $apiResult->setIndexedTagName_internal( array(
'query', $this->getModuleName()
), 'p' );
} else {
' score - Adds the score (if any) from the search engine',
' snippet - Adds a parsed snippet of the page',
' titlesnippet - Adds a parsed snippet of the page title',
- ' redirectsnippet - Adds a parsed snippet of the redirect',
- ' redirecttitle - Adds a parsed snippet of the redirect title',
- ' sectionsnippet - Adds a parsed snippet of the matching section',
- ' sectiontitle - Adds a parsed snippet of the matching section title',
+ ' redirectsnippet - Adds a parsed snippet of the redirect title',
+ ' redirecttitle - Adds the title of the matching redirect',
+ ' sectionsnippet - Adds a parsed snippet of the matching section title',
+ ' sectiontitle - Adds the title of the matching section',
' hasrelated - Indicates whether a related search is available',
),
'redirects' => 'Include redirect pages in the search',
);
}
+ public function getResultProperties() {
+ return array(
+ '' => array(
+ 'ns' => 'namespace',
+ 'title' => 'string'
+ ),
+ 'snippet' => array(
+ 'snippet' => 'string'
+ ),
+ 'size' => array(
+ 'size' => 'integer'
+ ),
+ 'wordcount' => array(
+ 'wordcount' => 'integer'
+ ),
+ 'timestamp' => array(
+ 'timestamp' => 'timestamp'
+ ),
+ 'score' => array(
+ 'score' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
+ 'titlesnippet' => array(
+ 'titlesnippet' => 'string'
+ ),
+ 'redirecttitle' => array(
+ 'redirecttitle' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
+ 'redirectsnippet' => array(
+ 'redirectsnippet' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
+ 'sectiontitle' => array(
+ 'sectiontitle' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
+ 'sectionsnippet' => array(
+ 'sectionsnippet' => array(
+ ApiBase::PROP_TYPE => 'string',
+ ApiBase::PROP_NULLABLE => true
+ )
+ ),
+ 'hasrelated' => array(
+ 'hasrelated' => 'boolean'
+ )
+ );
+ }
+
public function getDescription() {
return 'Perform a full text search';
}
) );
}
- protected function getExamples() {
+ public function getExamples() {
return array(
'api.php?action=query&list=search&srsearch=meaning',
'api.php?action=query&list=search&srwhat=text&srsearch=meaning',
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Search';
+ }
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}