Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Mar 20, 2024
1 parent 200f913 commit 97f04aa
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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' => [
Expand All @@ -495,21 +496,19 @@ 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',
],
'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');
Expand Down

0 comments on commit 97f04aa

Please sign in to comment.