Answer the question
In order to leave comments, you need to log in
How to properly implement property filters in Sphinx?
I am rewriting the bulletin board site from mySQL to SphinxSE - I am doing it on the Yii2 framework (yii \ sphinx \ Query)
I will describe the essence of the issue using a simplified example ...
In mySQL DB. there are tables `announces` and `options`, the first contains announcements (title, text, submission date, etc.), the second contains properties (property_name, value), one-to-many relationship:
`announces`.`id` -> `options`.ann_id
In Sphinx index settings I did this:
source announces
{
sql_query = \
SELECT `announces`.`id`, `announces`.`header`, `announces`.`description`, \
(SELECT JSON_OBJECTAGG(`option_id`, `value`) FROM `options` WHERE `options`.`ann_id` = `announces`.`id`) AS `filters`, \
и т.д.
sql_field_string = header
sql_field_string = description
sql_attr_json = filters
}
[filters] => {"422":"Toyota","423":"Prius","424":"Гибрид","425":"Автомат","426":"Передний","427":"Хэтчбэк","429":"Серый","430":1800,"431":2019]
$query = new Query(); // Sphinx
$query->from('announces')
->where(['disabled' => 0])
->andWhere( "filters['424'] = 'Гибрид'" )
->all();
->andWhere( " filters['424'] IN ( 'Бензин', 'Дизель', 'Газ' ) ") // Так не ищет в jSON :(
Answer the question
In order to leave comments, you need to log in
Sergei Tikhonov , yes, thanks!
It works. So:
$query = new Query(); // Sphinx
$query->from('announces');
$query->addSelect("*");
$query->addSelect(new Expression("IN(filters['424'], 'Бензин', 'Дизель', 'Газ') AS f_424"));
$query->andWhere("f_424 = 1");
$query-all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question