@@ -18,7 +18,7 @@ public function testSelect()
18
18
$ query = new Query ();
19
19
$ query ->select ('* ' );
20
20
$ this ->assertEquals (['* ' => '* ' ], $ query ->select );
21
- $ this ->assertNull ($ query ->distinct );
21
+ $ this ->assertFalse ($ query ->distinct );
22
22
$ this ->assertEquals (null , $ query ->selectOption );
23
23
24
24
$ query = new Query ();
@@ -458,6 +458,9 @@ public function testFacets()
458
458
{
459
459
$ connection = $ this ->getConnection ();
460
460
461
+ $ rawSphinxVersion = $ connection ->createCommand ("SHOW GLOBAL VARIABLES LIKE 'version' " )->queryOne ();
462
+ $ sphinxVersion = isset ($ rawSphinxVersion ['Value ' ]) ? $ rawSphinxVersion ['Value ' ] : '' ;
463
+
461
464
$ query = new Query ();
462
465
$ results = $ query ->from ('yii2_test_article_index ' )
463
466
->match ('about ' )
@@ -480,18 +483,33 @@ public function testFacets()
480
483
$ this ->assertNotEmpty ($ results ['hits ' ], 'Unable to query with complex facet ' );
481
484
$ this ->assertNotEmpty ($ results ['facets ' ]['author_id ' ], 'Unable to fill up complex facet ' );
482
485
483
- $ query = new Query ();
484
- $ results = $ query ->from ('yii2_test_article_index ' )
485
- ->match ('about ' )
486
- ->facets ([
487
- 'range ' => [
488
- 'select ' => 'INTERVAL(author_id,200,400,600,800) AS range ' ,
489
- ],
490
- 'authorId ' => [
491
- 'select ' => [new Expression ('author_id AS authorId ' )],
492
- ],
493
- ])
494
- ->search ($ connection );
486
+ $ query = (new Query ())
487
+ ->from ('yii2_test_article_index ' )
488
+ ->match ('about ' );
489
+
490
+ if (strpos ($ sphinxVersion , '3. ' ) === 0 ) {
491
+ $ query = $ query
492
+ ->select (new Expression ('INTERVAL(author_id,200,400,600,800) AS range ' ))
493
+ ->facets ([
494
+ 'range ' => [
495
+ 'select ' => 'range ' ,
496
+ ],
497
+ 'authorId ' => [
498
+ 'select ' => [new Expression ('author_id AS authorId ' )],
499
+ ],
500
+ ]);
501
+ } else {
502
+ $ query = $ query
503
+ ->facets ([
504
+ 'range ' => [
505
+ 'select ' => 'INTERVAL(author_id,200,400,600,800) AS range ' ,
506
+ ],
507
+ 'authorId ' => [
508
+ 'select ' => [new Expression ('author_id AS authorId ' )],
509
+ ],
510
+ ]);
511
+ }
512
+ $ results = $ query ->search ($ connection );
495
513
$ this ->assertNotEmpty ($ results ['hits ' ], 'Unable to query with facet using custom select ' );
496
514
$ this ->assertNotEmpty ($ results ['facets ' ]['range ' ], 'Unable to fill up facet using function in select ' );
497
515
$ this ->assertNotEmpty ($ results ['facets ' ]['authorId ' ], 'Unable to fill up facet using `Expression` in select ' );
0 commit comments