Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 33
QueryCompSuggestBuildDoc
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
56
0.00% covered (danger)
0.00%
0 / 33
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 execute
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 12
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 7
 addExplanation
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 12
<?php
namespace CirrusSearch\Api;
use ApiQuery;
use ApiQueryBase;
use CirrusSearch\BuildDocument\Completion\SuggestBuilder;
use Elastica\Document;
use InvalidArgumentException;
use Wikimedia\ParamValidator\ParamValidator;
class QueryCompSuggestBuildDoc extends ApiQueryBase {
    use ApiTrait;
    public function __construct( ApiQuery $query, $moduleName ) {
        parent::__construct( $query, $moduleName, 'csb' );
    }
    /**
     * @inheritDoc
     */
    public function execute() {
        $method = $this->getParameter( 'method' );
        try {
            $builder = SuggestBuilder::create( $this->getCirrusConnection(), $method );
        } catch ( InvalidArgumentException $e ) {
            $this->addError( 'apierror-compsuggestbuilddoc-bad-method' );
            return;
        }
        foreach ( $this->getPageSet()->getGoodTitles() as $origPageId => $title ) {
            $docs = $this->loadDocuments( $title );
            $this->addExplanation( $builder, $origPageId, $docs );
        }
    }
    protected function getAllowedParams() {
        return [
            'method' => [
                ParamValidator::PARAM_TYPE => 'string',
                ParamValidator::PARAM_DEFAULT => $this->getSearchConfig()->get( 'CirrusSearchCompletionDefaultScore' ),
            ],
        ];
    }
    private function addExplanation( SuggestBuilder $builder, $pageId, array $docs ) {
        $docs = array_map(
            static function ( Document $d ) {
                return [ $d->getId() => $d->getData() ];
            }, $builder->build( $docs, true )
        );
        foreach ( $docs as $doc ) {
            $this->getResult()->addValue(
                [ 'query', 'pages', $pageId ],
                'cirruscompsuggestbuilddoc',
                $doc
            );
        }
    }
}