From c9a46b6c9ff77cfdb3e7a8b64a63e5480074ea99 Mon Sep 17 00:00:00 2001 From: Pavel Piligrimov <p.piligrimov@iqdev.digital> Date: Mon, 12 Dec 2022 01:07:18 +0500 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=84?= =?UTF-8?q?=D0=B0=D1=81=D0=B5=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/FIlter/AggsTest.php | 243 +++++++++++++++++++++++++++++++++++++- 1 file changed, 237 insertions(+), 6 deletions(-) diff --git a/tests/FIlter/AggsTest.php b/tests/FIlter/AggsTest.php index 50fce3c..f8dced8 100644 --- a/tests/FIlter/AggsTest.php +++ b/tests/FIlter/AggsTest.php @@ -178,8 +178,8 @@ class AggsTest extends TestCase 0 => [ 'label' => null, 'value' => 'red', - 'count' => 0, - 'active' => false + 'count' => 1, + 'active' => true ], 1 => [ 'label' => null, @@ -405,8 +405,8 @@ class AggsTest extends TestCase 0 => [ 'label' => null, 'value' => 'red', - 'count' => 0, - 'active' => false + 'count' => 1, + 'active' => true ], 1 => [ 'label' => null, @@ -526,8 +526,8 @@ class AggsTest extends TestCase 1 => [ 'label' => null, 'value' => 'white', - 'count' => 0, - 'active' => false + 'count' => 1, + 'active' => true ] ], 'range' => [] @@ -583,4 +583,235 @@ class AggsTest extends TestCase $this->assertEqualsCanonicalizing($expected, FormatData::formatDataWFacets($result)); } + + public function testKeywordFilter() + { + $handler = SearchClient::getInstance(); + + $q = SearchQuery::createFromArray( + [ + 'filters' => [ + 'categoryId' => 't-short', + 'color' => ['white'], + 'brand' => ['nike'], + 'price' => ['min' => 100] + ] + ] + ); + $result = $handler->handle($q); + + $expected = [ + 'hits' => [ + 'h2' + ], + 'facets' => [ + 0 => [ + 'code' => 'brand', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'nike', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'rebook', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 1 => [ + 'code' => 'color', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'red', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'white', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 2 => [ + 'code' => 'size', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'xl', + 'count' => 0, + 'active' => false + ], + 1 => [ + 'label' => null, + 'value' => 'xxl', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 3 => [ + 'code' => 'price', + 'label' => null, + 'type' => 'range', + 'items' => [ + 'list' => [], + 'range' => [ + 0 => [ + 'label' => null, + 'count' => 1, + 'active' => true, + 'fullRange' => [ + 'min' => 104.0, + 'max' => 106.0 + ], + 'activeRange' => [ + 'min' => 105.0, + 'max' => 105.0 + ] + ] + ] + ] + ] + ] + ]; + + $this->assertEqualsCanonicalizing($expected, FormatData::formatDataWFacets($result)); + } + + public function testKeywordFilterTwo() + { + $handler = SearchClient::getInstance(); + + $q = SearchQuery::createFromArray( + [ + 'filters' => [ + 'categoryId' => 't-short', + 'color' => ['white'], + 'brand' => ['nike', 'reebok'] + ] + ] + ); + $result = $handler->handle($q); + + $expected = [ + 'hits' => [ + 'h2' + ], + 'facets' => [ + 0 => [ + 'code' => 'brand', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'nike', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'rebook', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 1 => [ + 'code' => 'color', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'red', + 'count' => 1, + 'active' => true + ], + 1 => [ + 'label' => null, + 'value' => 'white', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 2 => [ + 'code' => 'size', + 'label' => null, + 'type' => 'list', + 'items' => [ + 'list' => [ + 0 => [ + 'label' => null, + 'value' => 'xl', + 'count' => 0, + 'active' => false + ], + 1 => [ + 'label' => null, + 'value' => 'xxl', + 'count' => 1, + 'active' => true + ] + ], + 'range' => [] + ] + ], + 3 => [ + 'code' => 'price', + 'label' => null, + 'type' => 'range', + 'items' => [ + 'list' => [], + 'range' => [ + 0 => [ + 'label' => null, + 'count' => 1, + 'active' => true, + 'fullRange' => [ + 'min' => 104.0, + 'max' => 106.0 + ], + 'activeRange' => [ + 'min' => 105.0, + 'max' => 105.0 + ] + ] + ] + ] + ] + ] + ]; + + $this->assertEqualsCanonicalizing($expected, FormatData::formatDataWFacets($result)); + } } \ No newline at end of file -- GitLab