X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQuerySearch.php;h=ed6c3cb6191d7ef1427c99b571e664c969138cd5;hb=369f7e81df819b1345509330001369fd359e9927;hp=59d7e9f1b7c4f3e3b15bc6945956d62fe28dc334;hpb=fa6402516114f900194ab0203ff8878f9094bcab;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 59d7e9f1b7..ed6c3cb619 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -24,11 +24,6 @@ * @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 * @@ -69,6 +64,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $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 ); @@ -97,16 +95,17 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $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() ); } @@ -114,7 +113,9 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $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'] ); @@ -123,6 +124,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { // Silently skip broken and missing titles if ( $result->isBrokenTitle() || $result->isMissingRevision() ) { + $result = $matches->next(); continue; } @@ -159,7 +161,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } 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(); @@ -170,7 +172,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } // 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 ); @@ -179,10 +181,12 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } else { $titles[] = $title; } + + $result = $matches->next(); } if ( is_null( $resultPageSet ) ) { - $this->getResult()->setIndexedTagName_internal( array( + $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' ); } else { @@ -264,10 +268,10 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ' 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', @@ -276,6 +280,63 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ); } + 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'; } @@ -287,7 +348,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ) ); } - 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', @@ -295,6 +356,10 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ); } + public function getHelpUrls() { + return 'https://www.mediawiki.org/wiki/API:Search'; + } + public function getVersion() { return __CLASS__ . ': $Id$'; }