Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| QueryCompSuggestBuildDoc | |
0.00% |
0 / 23 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| getAllowedParams | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addExplanation | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Api; |
| 4 | |
| 5 | use CirrusSearch\BuildDocument\Completion\SuggestBuilder; |
| 6 | use InvalidArgumentException; |
| 7 | use MediaWiki\Api\ApiQuery; |
| 8 | use MediaWiki\Api\ApiQueryBase; |
| 9 | use Wikimedia\ParamValidator\ParamValidator; |
| 10 | |
| 11 | class QueryCompSuggestBuildDoc extends ApiQueryBase { |
| 12 | use ApiTrait; |
| 13 | |
| 14 | public function __construct( ApiQuery $query, string $moduleName ) { |
| 15 | parent::__construct( $query, $moduleName, 'csb' ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * @inheritDoc |
| 20 | */ |
| 21 | public function execute() { |
| 22 | $method = $this->getParameter( 'method' ); |
| 23 | try { |
| 24 | $builder = SuggestBuilder::create( $this->getCirrusConnection(), $method ); |
| 25 | } catch ( InvalidArgumentException ) { |
| 26 | $this->addError( 'apierror-compsuggestbuilddoc-bad-method' ); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | foreach ( $this->getPageSet()->getGoodPages() as $origPageId => $title ) { |
| 31 | $docs = $this->loadDocuments( $title ); |
| 32 | $this->addExplanation( $builder, $origPageId, $docs ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 37 | protected function getAllowedParams() { |
| 38 | return [ |
| 39 | 'method' => [ |
| 40 | ParamValidator::PARAM_TYPE => 'string', |
| 41 | ParamValidator::PARAM_DEFAULT => $this->getSearchConfig()->get( 'CirrusSearchCompletionDefaultScore' ), |
| 42 | ], |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Mark as internal. This isn't meant to be used by normal api users |
| 48 | * @return bool |
| 49 | */ |
| 50 | public function isInternal() { |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | private function addExplanation( SuggestBuilder $builder, int $pageId, array $docs ) { |
| 55 | $result = $this->getResult(); |
| 56 | foreach ( $builder->build( $docs, true ) as $d ) { |
| 57 | $result->addValue( |
| 58 | [ 'query', 'pages', $pageId ], |
| 59 | 'cirruscompsuggestbuilddoc', |
| 60 | [ $d->getId() => $d->getData() ] |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | } |