From 3da5aacce984a574e0603e8e88bedecefb646865 Mon Sep 17 00:00:00 2001 From: Michal Paulovic Date: Thu, 24 Mar 2022 13:26:17 +0100 Subject: [PATCH 1/3] add DISTINCT in FACET for manticoresearch 4.x --- src/Facet.php | 10 ++++++++++ tests/SphinxQL/FacetTest.php | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Facet.php b/src/Facet.php index e9d8a038..e35d9068 100644 --- a/src/Facet.php +++ b/src/Facet.php @@ -329,4 +329,14 @@ public function getFacet() { return $this->compileFacet()->query; } + + /** + * @param $distinct + * @return Facet + */ + public function distinct($distinct) + { + $this->distinct_by = $distinct; + return $this; + } } diff --git a/tests/SphinxQL/FacetTest.php b/tests/SphinxQL/FacetTest.php index 4bf8975d..388214d4 100644 --- a/tests/SphinxQL/FacetTest.php +++ b/tests/SphinxQL/FacetTest.php @@ -141,4 +141,14 @@ public function testLimit() $this->assertEquals('FACET gid, title ORDER BY COUNT(*) DESC LIMIT 5, 5', $facet); } + + public function testDistinct() + { + $facet = Facet::create(self::$conn) + ->facet(array('gid', 'title')) + ->distinct('title') + ->getFacet(); + + $this->assertEquals('FACET gid, title DISTINCT title', $facet); + } } From 3530ba000cc003f1f2e28a691860d9fa1f29f72e Mon Sep 17 00:00:00 2001 From: Michal Paulovic Date: Thu, 24 Mar 2022 13:27:37 +0100 Subject: [PATCH 2/3] reformat --- tests/SphinxQL/FacetTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/SphinxQL/FacetTest.php b/tests/SphinxQL/FacetTest.php index 388214d4..4ff2fa85 100644 --- a/tests/SphinxQL/FacetTest.php +++ b/tests/SphinxQL/FacetTest.php @@ -142,13 +142,13 @@ public function testLimit() $this->assertEquals('FACET gid, title ORDER BY COUNT(*) DESC LIMIT 5, 5', $facet); } - public function testDistinct() - { - $facet = Facet::create(self::$conn) - ->facet(array('gid', 'title')) - ->distinct('title') - ->getFacet(); - - $this->assertEquals('FACET gid, title DISTINCT title', $facet); - } + public function testDistinct() + { + $facet = Facet::create(self::$conn) + ->facet(array('gid', 'title')) + ->distinct('title') + ->getFacet(); + + $this->assertEquals('FACET gid, title DISTINCT title', $facet); + } } From 6b33d0cad9b919cfcf0ae654bdd8b7d4a12a61e7 Mon Sep 17 00:00:00 2001 From: Michal Paulovic Date: Thu, 24 Mar 2022 13:49:19 +0100 Subject: [PATCH 3/3] define property --- src/Facet.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Facet.php b/src/Facet.php index e35d9068..f4f90b8a 100644 --- a/src/Facet.php +++ b/src/Facet.php @@ -61,6 +61,13 @@ class Facet */ protected $limit = null; + /** + * Faceting without duplicates + * + * @var null|string + */ + protected $distinct_by = null; + public function __construct(ConnectionInterface $connection = null, $static = false) { $this->connection = $connection;