diff --git a/src/Facet.php b/src/Facet.php index e9d8a038..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; @@ -329,4 +336,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..4ff2fa85 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); + } }