Skip to content

JSON fields support #80

@yschapov

Description

@yschapov

This is very real. Users post problems they experience with JSON fields, i.e.:

$conn = new Connection();
  $query = SphinxQL::create($conn)->select('product_id')->from('parameter_index');
  if (!empty($data['minCoast']) and !empty($data['maxCoast'] and ($data['minCoast'] <  $data['maxCoast']) )) {
  $query -> where('attr.coast', 'BETWEEN', [$data['minCoast'],$data['maxCoast']]);
}

if (!empty($data['catalog'])) {
  $query -> where('attr.catalog_id', '=', $data['catalog']);
}
$total = $query->execute();

It causes an error:

syntax error, unexpected $undefined, expecting IDENT (or 97 other tokens) near 'attr[coast]BETWEEN '1000' AND '7000' ANDattr[catalog_id]= '2'' [ SELECTproduct_idFROMparameter_indexWHEREattr[coast]BETWEEN '1000' AND '7000' ANDattr[catalog_id]` = '2']``

The matter is 'attr.catalog_id' and 'attr.coast' are JSON fields. A working request would be (note that backticks were partially removed):

attr["coast"] BETWEEN '1000' AND '7000' AND attr["catalog_id"] = '2'' [ SELECT product_idFROMparameter_index WHERE attr["coast"] BETWEEN '1000' AND '7000' AND attr["catalog_id"] = '2'

This is because Sphinx currently cannot parse JSON fields that are surrounded by backticks. MySQL wouldn't parse that syntax either, e.g. test.table surrounded with backticks wil end up with a syntax error.

I suggest removing backticks as a whole (Sphinx fields can't contain spaces anyway) or at least remove backticks from JSON fields.

Also I noticed that attr.catalog_id becomes attr[catalog_id] which is also wrong (not sure if it's Query builder or user's request though). The proper syntax would be either attr.catalog_id or attr["catalog_id"].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions