Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 64 additions and 83 deletions
<?php
namespace IQDEV\ElasticSearch\Request\Order;
namespace IQDEV\ElasticSearch\Criteria\Order;
use IQDEV\ElasticSearch\Esable;
use Ramsey\Collection\AbstractCollection;
......
<?php
namespace IQDEV\ElasticSearch\Request\Order;
namespace IQDEV\ElasticSearch\Criteria\Order;
enum OrderDirection: string
{
......
<?php
namespace IQDEV\ElasticSearch\Request\Order;
namespace IQDEV\ElasticSearch\Criteria\Order;
use IQDEV\ElasticSearch\Document\Property\Property;
use IQDEV\ElasticSearch\Document\Property\PropertyType;
use IQDEV\ElasticSearch\Request\Order\Type\BaseOrder;
use IQDEV\ElasticSearch\Request\Order\Type\KeywordPropertyOrder;
use IQDEV\ElasticSearch\Request\Order\Type\NumberPropertyOrder;
use IQDEV\ElasticSearch\Criteria\Order\Type\BaseOrder;
use IQDEV\ElasticSearch\Criteria\Order\Type\KeywordPropertyOrder;
use IQDEV\ElasticSearch\Criteria\Order\Type\NumberPropertyOrder;
class OrderFactory
{
......
<?php
namespace IQDEV\ElasticSearch\Request\Order\Type;
namespace IQDEV\ElasticSearch\Criteria\Order\Type;
use IQDEV\ElasticSearch\Request\Order\Order;
use IQDEV\ElasticSearch\Criteria\Order\Order;
class BaseOrder extends Order
{
......
<?php
namespace IQDEV\ElasticSearch\Request\Order\Type;
namespace IQDEV\ElasticSearch\Criteria\Order\Type;
use IQDEV\ElasticSearch\Request\Order\Order;
use IQDEV\ElasticSearch\Criteria\Order\Order;
class KeywordPropertyOrder extends Order
{
......
<?php
namespace IQDEV\ElasticSearch\Request\Order\Type;
namespace IQDEV\ElasticSearch\Criteria\Order\Type;
use IQDEV\ElasticSearch\Request\Order\Order;
use IQDEV\ElasticSearch\Criteria\Order\Order;
class NumberPropertyOrder extends Order
{
......
<?php
namespace IQDEV\ElasticSearch;
namespace IQDEV\ElasticSearch\Criteria;
final class Pagination
{
......
<?php
namespace IQDEV\ElasticSearch\Request\Query;
namespace IQDEV\ElasticSearch\Criteria\Query;
use IQDEV\ElasticSearch\Criteria;
use IQDEV\ElasticSearch\Criteria\Criteria;
final class SearchQuery
{
......
<?php
namespace IQDEV\ElasticSearch\Request\Query;
namespace IQDEV\ElasticSearch\Criteria\Query;
use IQDEV\ElasticSearch\SearchService;
......
<?php
namespace IQDEV\ElasticSearch\Request\Query;
namespace IQDEV\ElasticSearch\Criteria\Query;
use IQDEV\ElasticSearch\Result;
......
......@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace IQDEV\ElasticSearch\Request\Search;
namespace IQDEV\ElasticSearch\Criteria\Search;
use IQDEV\ElasticSearch\Document\Property\Property;
......@@ -10,7 +10,7 @@ class Search
{
public function __construct(
private readonly Property $property,
private readonly string $value,
private readonly mixed $value,
) {
}
......@@ -19,7 +19,7 @@ class Search
return $this->property;
}
public function getValue(): string
public function getValue(): mixed
{
return $this->value;
}
......
<?php
namespace IQDEV\ElasticSearch\Request\Search;
namespace IQDEV\ElasticSearch\Criteria\Search;
use Ramsey\Collection\AbstractCollection;
......
......@@ -2,11 +2,11 @@
declare(strict_types=1);
namespace IQDEV\ElasticSearch\Request\Search;
namespace IQDEV\ElasticSearch\Criteria\Search;
use IQDEV\ElasticSearch\Config\MappingValidator;
use IQDEV\ElasticSearch\Configuration;
use IQDEV\ElasticSearch\Request\Match\QueryMatch;
use IQDEV\ElasticSearch\Criteria\Match\QueryMatch;
use IQDEV\ElasticSearch\Search\BoolQuery\Query;
use IQDEV\ElasticSearch\Search\BoolQuery\Terms;
use IQDEV\ElasticSearch\Search\Nested;
......
......@@ -113,7 +113,7 @@ class ProductDocument implements Document
$result = array_replace_recursive($document, $this->properties);
if (true === $this->skipEmpty) {
$result = ArrayHelper::array_filter_recursive($result);
$result = ArrayHelper::array_filter_recursive($result, static fn ($val) => $val !== null || $val === false);
}
return $result;
......
......@@ -11,9 +11,13 @@ final class KeywordFacet extends Facet
*/
public function es(): array
{
$value = is_array($this->value) ?
array_map(static fn($value) => (string) $value, $this->value) :
(string) $this->value;
return [
'facet_code' => $this->property->getKey(),
'facet_value' => (string) $this->value,
'facet_value' => $value
];
}
}
......@@ -53,7 +53,7 @@ final class EsHelperEndpoint
[
'index' => $this->configuration->getIndexName(),
'body' => [
'mappings' => $this->configuration->getMapping()->es(),
'mappings' => $this->configuration->getMapping(),
'settings' => $this->configuration->getSettings(),
],
]
......@@ -99,7 +99,7 @@ final class EsHelperEndpoint
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
$this->configuration->getMapping()->es(),
$this->configuration->getMapping(),
)
);
......
<?php
declare(strict_types=1);
namespace IQDEV\ElasticSearch;
abstract class Mapping implements Esable
{
abstract public function getPropertiesMap(): array;
public function getSearchDataMap(): array
{
return [
'type' => 'nested',
'properties' => [
'keyword_facet' => [
'type' => 'nested',
'properties' => [
'facet_code' => [
'type' => 'keyword',
'index' => true
],
'facet_value' => [
'type' => 'keyword',
'index' => true
]
]
],
'number_facet' => [
'type' => 'nested',
'properties' => [
'facet_code' => [
'type' => 'keyword',
'index' => true
],
'facet_value' => [
'type' => 'double'
]
]
]
]
];
}
public function es(): array
{
return [
'properties' => array_merge(
$this->getPropertiesMap(),
['search_data' => $this->getSearchDataMap()],
)
];
}
}
......@@ -3,7 +3,7 @@
namespace IQDEV\ElasticSearch\Search\BoolQuery;
use IQDEV\ElasticSearch\Esable;
use IQDEV\ElasticSearch\Request\Filter\FilterOperator;
use IQDEV\ElasticSearch\Criteria\Filter\FilterOperator;
use IQDEV\ElasticSearch\Search\Nested;
final class FilterNumberFacet implements Esable
......
......@@ -118,4 +118,34 @@ final class Query implements Esable
],
];
}
public function modify(Query $another): self
{
foreach ($another->getMust() as $item) {
$this->getMust()->add($item);
}
foreach ($another->getFilter() as $item) {
$this->getFilter()->add($item);
}
foreach ($another->getShould() as $item) {
$this->getShould()->add($item);
}
foreach ($another->getMustNot() as $item) {
$this->getMustNot()->add($item);
}
foreach ($another->getMatch() as $item) {
$this->getMatch()->add($item);
}
return $this;
}
public function __clone(): void
{
$this->must = clone $this->must;
$this->should = clone $this->should;
$this->filter = clone $this->filter;
$this->mustNot = clone $this->mustNot;
$this->match = clone $this->match;
}
}
......@@ -8,11 +8,11 @@ final class Terms implements Esable
{
/**
* @param string $key
* @param string|float|array<string|float> $value
* @param string|float|bool|array<string|float> $value
*/
public function __construct(
private string $key,
private string|float|array $value
private mixed $value
) {
}
......