I
I
Ivan Koryukov2016-07-22 14:23:05
Sphinx
Ivan Koryukov, 2016-07-22 14:23:05

How to write a request to Sphinx using yii-sphinx?

Good afternoon.
I have Sphinx 2.0.4 with this configuration:

source tickets
{
    type        = mysql
    sql_host    = db
    sql_user    = db_user
    sql_pass    = db_pass
    sql_db      = db_name
    sql_port    = 3306 

    sql_query_pre = SET NAMES utf8
    sql_query_pre = SET CHARACTER SET utf8

    sql_query   = SELECT id, title, description, image_small, pay, created, slug, type, pay_period_id,currency_id \
    city_id FROM ticket

    sql_field_string = title
    sql_field_string = description
    
    sql_attr_string = slug
    sql_attr_string = image_small

    sql_attr_timestamp = created
    sql_attr_uint = type
    sql_attr_uint = pay
    
    sql_attr_uint = user_id
    sql_attr_uint = pay_period_id
    sql_attr_uint = currency_id
    sql_attr_uint = city_id

    sql_attr_multi	= uint tag_ids from query; SELECT ticket_id, tag_id FROM ticket_tag
}

Using the yiisoft/yii2-sphinx extension, I make a request like this:
$query = SphinxTicket::find();
$query->where(['type'=>$type]);
if($this->match){
    $query->match($this->match);
}
if($this->pay_min) $query->andWhere(['>=','pay',$this->pay_min]);
if($this->pay_max) $query->andWhere(['<=','pay',$this->pay_max]);

In response I get the following error:
SQLSTATE[42000]: Syntax error or access violation: 1064 sphinxql: syntax error, unexpected '(', expecting IDENT (or 5 other tokens) near '((`type`=1) AND (`pay` >= '1000')) AND (`pay` <= '100000') LIMIT 2; SHOW META'
The SQL being executed was: SELECT * FROM `tickets_index` WHERE ((`type`=1) AND (`pay` >= '1000')) AND (`pay` <= '100000') LIMIT 2; SHOW META

How is it necessary to make a query to Sphinx in order to select records by multiple fields + match?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Koryukov, 2016-07-24
@MadridianFox

Actually the problem was in Sphinx version. After updating to 2.2.9, both queries with brackets and queries that directly access the id field began to work (previously only @id worked),

Пума Тайланд, 2016-07-22
@opium

может стоит почитать про сфинкс и диалект sphinxql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question