Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CountContentWordsBuilder | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
build | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Query; |
4 | |
5 | use CirrusSearch\Search\SearchContext; |
6 | use CirrusSearch\Search\SingleAggResultsType; |
7 | use Elastica\Aggregation\Sum; |
8 | |
9 | /** |
10 | * Build a query to sum up the word count of all articles |
11 | */ |
12 | class 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 | } |