yii\sphinx\Query::createCommand PHP Method

createCommand() public method

Creates a Sphinx command that can be used to execute this query.
public createCommand ( Connection $db = null ) : Command
$db Connection the Sphinx connection used to generate the SQL statement. If this parameter is not given, the `sphinx` application component will be used.
return Command the created Sphinx command instance.
    public function createCommand($db = null)
    {
        $this->setConnection($db);
        $db = $this->getConnection();
        list($sql, $params) = $db->getQueryBuilder()->build($this);
        return $db->createCommand($sql, $params);
    }

Usage Example

Example #1
0
 public function testMatch()
 {
     $query = new Query();
     $match = 'test match';
     $query->match($match);
     $this->assertEquals($match, $query->match);
     $command = $query->createCommand($this->getConnection(false));
     $this->assertContains('MATCH(', $command->getSql(), 'No MATCH operator present!');
     $this->assertContains($match, $command->params, 'No match query among params!');
 }