Newer
Older
use IQDEV\ElasticSearch\Config\MappingValidator;
use IQDEV\ElasticSearch\Configuration;
use IQDEV\ElasticSearch\Facet\Collection\FacetCollection;
use IQDEV\ElasticSearch\Facet\Facet;
private FacetCollection $keywordFacets;
private FacetCollection $numberFacets;
private ?string $searchContent = null;
private array $info = [];
private bool $skipEmpty = false;
$this->keywordFacets = new FacetCollection();
$this->numberFacets = new FacetCollection();
public static function create(Facet $categoryFacet): self
}
/**
* @return FacetCollection
*/
public function getKeywordFacets(): FacetCollection
{
return $this->keywordFacets;
}
/**
{
return $this->categoryFacet;
}
/**
* @return FacetCollection
*/
public function getNumberFacets(): FacetCollection
{
return $this->numberFacets;
}
/**
public function setSearchContent(?string $searchContent): void
61
62
63
64
65
66
67
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
$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, static fn ($val) => $val !== null || $val === false);