Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx facet not work with json attribute when use QueryBuilder #8579

Closed
InteLigent opened this issue May 27, 2015 · 7 comments
Closed

Sphinx facet not work with json attribute when use QueryBuilder #8579

InteLigent opened this issue May 27, 2015 · 7 comments

Comments

@InteLigent
Copy link

use php example:

$facets = ['attr.fg_3'];
foreach ($filter_groups as $ftg) {
    $facets[] = 'attr.fg_'.$ftg['filter_group_id'];
}
$query->facets($facets);

Final SphinxQL:

SQLSTATE[42000]: Syntax error or access violation: 1064 sphinxql: syntax error, unexpected '.', expecting $end near '.`fg_3` AS `attr_fg_3` ; SHOW META'
The SQL being executed was: SELECT `id` FROM `product` WHERE category_id = 72 ORDER BY `date_modified` DESC LIMIT 16 FACET `attr`.`fg_3` AS `attr_fg_3` ; SHOW META
@klimov-paul
Copy link
Member

What whould be valid SphinxQL for your case?

@InteLigent
Copy link
Author

I have been edit subject above.

Is correct SphinxQL:

SELECT id FROM product WHERE category_id = 72 ORDER BY date_modified DESC LIMIT 16 FACET attr.fg_3 AS attr_fg_3 ; SHOW META

@klimov-paul
Copy link
Member

You should use yii\db\Expression for your case:

$query->facets([
    'jsonAttr' => [
        'select' => [new \yii\db\Expression('attr.fg_1')]
    ],
]);

@InteLigent
Copy link
Author

I get following error:

PHP Notice – yii\base\ErrorException

Undefined index: jsonAttr

at line 228 in file .../vendor/yiisoft/yii2-sphinx/Query.php

@klimov-paul klimov-paul reopened this May 29, 2015
@klimov-paul klimov-paul added the status:to be verified Needs to be reproduced and validated. label May 29, 2015
@klimov-paul
Copy link
Member

There must be correspondance between facet name and select expression.
So you shuld either name facet 'attr.fg_1':

$query->facets([
    'attr.fg_1' => [
        'select' => [new \yii\db\Expression('attr.fg_1')]
    ],
]);

Or use alias for selected expression with facet name:

$query->facets([
    'jsonAttr' => [
        'select' => [new \yii\db\Expression('attr.fg_1 AS jsonAttr')]
    ],
]);

Still there is a bug, which does not respects camel-case facet names.
Fix is on the way.

@klimov-paul klimov-paul added type:bug Bug and removed status:to be verified Needs to be reproduced and validated. labels Jun 2, 2015
@klimov-paul
Copy link
Member

Migrated to yiisoft/yii2-sphinx#21

@klimov-paul
Copy link
Member

Fix and doc updates:
yiisoft/yii2-sphinx@0d53300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants