Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
42.86% |
3 / 7 |
CRAP | |
70.83% |
17 / 24 |
FullTextResultsType | |
0.00% |
0 / 1 |
|
42.86% |
3 / 7 |
8.22 | |
70.83% |
17 / 24 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
getSourceFiltering | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
getStoredFields | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getHighlightingConfiguration | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
transformElasticsearchResult | |
0.00% |
0 / 1 |
1.03 | |
70.00% |
7 / 10 |
|||
withFetchPhaseBuilder | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
createEmptyResult | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
namespace CirrusSearch\Search; | |
use CirrusSearch\Search\Fetch\FetchPhaseConfigBuilder; | |
use Elastica\ResultSet as ElasticaResultSet; | |
/** | |
* Result type for a full text search. | |
*/ | |
final class FullTextResultsType extends BaseResultsType { | |
/** | |
* @var bool | |
*/ | |
private $searchContainedSyntax; | |
/** | |
* @var FetchPhaseConfigBuilder | |
*/ | |
private $fetchPhaseBuilder; | |
/** | |
* @var TitleHelper | |
*/ | |
private $titleHelper; | |
/** | |
* @var string[] list of extra fields to extract | |
*/ | |
private $extraFieldsToExtract; | |
/** | |
* @param FetchPhaseConfigBuilder $fetchPhaseBuilder | |
* @param bool $searchContainedSyntax | |
* @param TitleHelper $titleHelper | |
* @param string[] $extraFieldsToExtract | |
*/ | |
public function __construct( | |
FetchPhaseConfigBuilder $fetchPhaseBuilder, | |
$searchContainedSyntax, | |
TitleHelper $titleHelper, | |
array $extraFieldsToExtract = [] | |
) { | |
$this->fetchPhaseBuilder = $fetchPhaseBuilder; | |
$this->searchContainedSyntax = $searchContainedSyntax; | |
$this->titleHelper = $titleHelper; | |
$this->extraFieldsToExtract = $extraFieldsToExtract; | |
} | |
/** | |
* @return false|string|array corresponding to Elasticsearch source filtering syntax | |
*/ | |
public function getSourceFiltering() { | |
return array_merge( | |
parent::getSourceFiltering(), | |
[ 'redirect.*', 'timestamp', 'text_bytes' ], | |
$this->extraFieldsToExtract | |
); | |
} | |
/** | |
* @return array | |
*/ | |
public function getStoredFields() { | |
return [ "text.word_count" ]; // word_count is only a stored field and isn't part of the source. | |
} | |
/** | |
* Setup highlighting. | |
* Don't fragment title because it is small. | |
* Get just one fragment from the text because that is all we will display. | |
* Get one fragment from redirect title and heading each or else they | |
* won't be sorted by score. | |
* | |
* @param array $extraHighlightFields (deprecated and ignored) | |
* @return array|null of highlighting configuration | |
*/ | |
public function getHighlightingConfiguration( array $extraHighlightFields = [] ) { | |
$this->fetchPhaseBuilder->configureDefaultFullTextFields(); | |
return $this->fetchPhaseBuilder->buildHLConfig(); | |
} | |
/** | |
* @param ElasticaResultSet $result | |
* @return CirrusSearchResultSet | |
*/ | |
public function transformElasticsearchResult( ElasticaResultSet $result ) { | |
// Should we make this a concrete class? | |
return new class( $this->titleHelper, $this->fetchPhaseBuilder, $result, $this->searchContainedSyntax, $this->extraFieldsToExtract ) | |
extends BaseCirrusSearchResultSet { | |
/** @var TitleHelper */ | |
private $titleHelper; | |
/** @var FullTextCirrusSearchResultBuilder */ | |
private $resultBuilder; | |
/** @var ElasticaResultSet */ | |
private $results; | |
/** @var bool */ | |
private $searchContainedSyntax; | |
public function __construct( | |
TitleHelper $titleHelper, | |
FetchPhaseConfigBuilder $builder, | |
ElasticaResultSet $results, | |
$searchContainedSyntax, | |
array $extraFieldsToExtract | |
) { | |
$this->titleHelper = $titleHelper; | |
$this->resultBuilder = new FullTextCirrusSearchResultBuilder( $this->titleHelper, | |
$builder->getHLFieldsPerTargetAndPriority(), $extraFieldsToExtract ); | |
$this->results = $results; | |
$this->searchContainedSyntax = $searchContainedSyntax; | |
} | |
/** | |
* @inheritDoc | |
*/ | |
protected function transformOneResult( \Elastica\Result $result ) { | |
return $this->resultBuilder->build( $result ); | |
} | |
/** | |
* @return \Elastica\ResultSet|null | |
*/ | |
public function getElasticaResultSet() { | |
return $this->results; | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function searchContainedSyntax() { | |
return $this->searchContainedSyntax; | |
} | |
protected function getTitleHelper(): TitleHelper { | |
return $this->titleHelper; | |
} | |
}; | |
} | |
/** | |
* @param FetchPhaseConfigBuilder $builder | |
* @return FullTextResultsType | |
*/ | |
public function withFetchPhaseBuilder( FetchPhaseConfigBuilder $builder ): FullTextResultsType { | |
return new self( $builder, $this->searchContainedSyntax, $this->titleHelper ); | |
} | |
/** | |
* @return CirrusSearchResultSet | |
*/ | |
public function createEmptyResult() { | |
return BaseCirrusSearchResultSet::emptyResultSet(); | |
} | |
} |