Newer
Older
use IQDEV\ElasticSearch\Config\MappingValidator;
use IQDEV\ElasticSearch\Configuration;
use IQDEV\ElasticSearch\Facet\FacetCategory;
use IQDEV\ElasticSearch\Facet\FacetCollection;
private FacetCollection $keywordFacets;
private FacetCollection $numberFacets;
private ?string $searchContent = null;
private array $info = [];
private bool $skipEmpty = false;
public function __construct(
FacetCategory $categoryFacet
)
{
$this->keywordFacets = new FacetCollection();
$this->numberFacets = new FacetCollection();
}
public static function create(FacetCategory $categoryFacet): self
{
return new self($categoryFacet);
}
/**
* @return FacetCollection
*/
public function getKeywordFacets(): FacetCollection
{
return $this->keywordFacets;
}
/**
* @return FacetCategory
*/
public function getCategoryFacet(): FacetCategory
{
return $this->categoryFacet;
}
/**
* @return FacetCollection
*/
public function getNumberFacets(): FacetCollection
{
return $this->numberFacets;
}
/**
public function setSearchContent(?string $searchContent): void
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
$this->searchContent = $searchContent;
}
public function setAdditionData(array $info): self
{
$this->info = $info;
return $this;
}
/**
* Установка значения свойства документа индекса по параметрам конфигурации.
* Имеет приоритет по сравнению с вызовами функций для установки данных.
*
* @param Configuration $configuration
* @param string $property
* @param $value
*
* @return $this
*/
public function setByConfiguration(Configuration $configuration, string $property, $value): self
{
if (!MappingValidator::isPropertyExists($configuration, $property)) {
throw new \InvalidArgumentException('Property ' . $property . ' doesnt exist');
}
$this->properties[$property] = $value;
return $this;
}
public function skipEmpty(bool $skipEmpty = false): self
{
$this->skipEmpty = $skipEmpty;
return $this;
}
public function es(): array
{
$document = [
'category_id' => $this->getCategoryFacet()->es()['category_id'],
'search_data' => [
'keyword_facet' => $this->getKeywordFacets()->es(),
'number_facet' => $this->getNumberFacets()->es()
],
'data' => $this->info
if (isset($this->searchContent)) {
$document['full_search_content'] = $this->searchContent;
$document['suggest_search_content'] = $this->searchContent;
}
$result = array_replace_recursive($document, $this->properties);
if (true === $this->skipEmpty) {
$result = ArrayHelper::array_filter_recursive($result);