Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
CountContentWordsBuilder
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 build
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace CirrusSearch\Query;
4
5use CirrusSearch\Search\SearchContext;
6use CirrusSearch\Search\SingleAggResultsType;
7use Elastica\Aggregation\Sum;
8
9/**
10 * Build a query to sum up the word count of all articles
11 */
12class CountContentWordsBuilder {
13    // The count doesn't change all that quickly. Re-run the query
14    // no more than daily per-wiki.
15    private const CACHE_SECONDS = 86400;
16
17    /**
18     * @param SearchContext $context the search context
19     */
20    public function build( SearchContext $context ) {
21        $context->addSyntaxUsed( 'sum_word_count' );
22        $context->setResultsType( new SingleAggResultsType( 'word_count' ) );
23        $context->setRescoreProfile( 'empty' );
24        $context->addAggregation(
25            ( new Sum( 'word_count' ) )->setField( 'text.word_count' ) );
26        $context->setCacheTtl( self::CACHE_SECONDS );
27    }
28}