From 97f04aa653b3f794169957e75141eed7b0f5d126 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 20 Mar 2024 13:57:12 +0300 Subject: [PATCH] fix --- tests/QueryTest.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/QueryTest.php b/tests/QueryTest.php index da2440f9..f7697fc4 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -458,6 +458,8 @@ public function testFacets() { $connection = $this->getConnection(); + $sphinxVersion = $connection->createCommand("SHOW GLOBAL VARIABLES LIKE 'version'")->queryOne()['Value'] ?? ''; + $query = new Query(); $results = $query->from('yii2_test_article_index') ->match('about') @@ -484,9 +486,8 @@ public function testFacets() ->from('yii2_test_article_index') ->match('about'); - try { - // Sphinx ^3 - $results = $query + if (strpos($sphinxVersion, '3.') === 0) { + $query = $query ->select(new Expression('INTERVAL(author_id,200,400,600,800) AS range')) ->facets([ 'range' => [ @@ -495,11 +496,9 @@ public function testFacets() 'authorId' => [ 'select' => [new Expression('author_id AS authorId')], ], - ]) - ->search($connection); - } catch (\PDOException $e) { - // Sphinx ^2 - $results = $query + ]); + } else { + $query = $query ->facets([ 'range' => [ 'select' => 'INTERVAL(author_id,200,400,600,800) AS range', @@ -507,9 +506,9 @@ public function testFacets() 'authorId' => [ 'select' => [new Expression('author_id AS authorId')], ], - ]) - ->search($connection); + ]); } + $results = $query->search($connection); $this->assertNotEmpty($results['hits'], 'Unable to query with facet using custom select'); $this->assertNotEmpty($results['facets']['range'], 'Unable to fill up facet using function in select'); $this->assertNotEmpty($results['facets']['authorId'], 'Unable to fill up facet using `Expression` in select');