Yii2 Sphinx 左连接不起作用

Yii2 Sphinx Left join not working

我一直在尝试使用 Yii-Sphinx 扩展,当我使用一个简单的查询时它工作正常,但是当我尝试使用左连接时它不起作用。它 returns 以下错误。我测试了很多查询但没有工作。我正在使用 Yii-Sphinx 扩展

SQLSTATE[42000]: Syntax error or access violation: 1064 sphinxql: syntax  
error, unexpected IDENT, expecting $end near 'LEFT JOIN specs ON specs.id =   
listing.specs_id'
The SQL being executed was: SELECT specs.id, listing.title,listing.specs_id,    
listing.reg_no, listing.price, listing.status, listing.featured FROM listing   
LEFT JOIN specs ON specs.id = listing.specs_id
Error Info: Array
(
    [0] => 42000
    [1] => 1064
    [2] => sphinxql: syntax error, unexpected IDENT, expecting $end near   
    'LEFT JOIN specs ON specs.id = listing.specs_id'
 )

这是我的查询

SELECT specs.id, listing.title,listing.specs_id, listing.reg_no,  listing.price, listing.status, listing.featured FROM listing LEFT JOIN specs ON specs.id = listing.specs_id

SphinxSearch 本身不支持 'JOIN'。它不能 运行 这样的查询。

yii2-sphinx 没有问题,这就是 Sphinx 的工作原理。

如果直接编写 SphinxQL 查询,可以在此处阅读 SELECT 语法: http://sphinxsearch.com/docs/current.html#sphinxql-select

SELECT statement was introduced in version 0.9.9-rc2. It's syntax is based upon regular SQL but adds several Sphinx-specific extensions and has a few omissions (such as (currently) missing support for JOINs).

一般使用QueryBuilder http://www.yiiframework.com/doc-2.0/yii-sphinx-querybuilder.html 因为它只提供 Sphinx 实际支持的 'methods'。

我已经解决了这个问题。这是任何陷入此类问题的人的详细信息。以下是我在 yii2-sphinx 扩展中使用 sphinx 查询生成器的解决方案:

$q = new Query();
$q->from('listing');
$rows = $q->all();

'listing'是来自sphinx配置文件的索引,Join查询可以写成sql_query

我做错了什么,我使用的是简单查询而不是查询生成器,这解决了问题。例如,连接查询将不适用于以下代码。

 $sql = 'Select * FROM listing';
 $rows = Yii::$app->sphinx->createCommand($sql)->queryAll(); 

将执行简单查询,但任何连接的查询都会return错误。