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 0bd135f commit 4aea790
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 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 @@ -480,19 +482,33 @@ public function testFacets()
$this->assertNotEmpty($results['hits'], 'Unable to query with complex facet');
$this->assertNotEmpty($results['facets']['author_id'], 'Unable to fill up complex facet');

$query = new Query();
$results = $query->from('yii2_test_article_index')
->match('about')
->select(new Expression('INTERVAL(author_id,200,400,600,800) AS range'))
->facets([
'range' => [
'select' => 'range',
],
'authorId' => [
'select' => [new Expression('author_id AS authorId')],
],
])
->search($connection);
$query = (new Query())
->from('yii2_test_article_index')
->match('about');

if (strpos($sphinxVersion, '2.') === 0) {
$query = $query
->facets([
'range' => [
'select' => 'INTERVAL(author_id,200,400,600,800) AS range',
],
'authorId' => [
'select' => [new Expression('author_id AS authorId')],
],
]);
} else {
$query = $query
->select(new Expression('INTERVAL(author_id,200,400,600,800) AS range'))
->facets([
'range' => [
'select' => 'range',
],
'authorId' => [
'select' => [new Expression('author_id AS authorId')],
],
]);
}
$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 4aea790

Please sign in to comment.