Ниже мой код выборки для sphinx. У нас есть фильтр с именем typeId, который мы используем для сравнения типа бюро. Теперь я добавил еще один фильтр с именем altTypeId. Теперь мне нужно сравнить typeId и altTypeId для одного и того же значения, такого как typeId = 6 ИЛИ altTypeId = 6.
Я пробовал несколько решений, но никто не работает. Я следовал решению по этой ссылке: https://sphx.org/forum/view.html?id=13474, но оно тоже не работает.
protected function fetch() {
$this->_searchCriteria->orders = $this->sort;
$this->pagination->validateCurrentPage = false;
$this->_searchCriteria->paginator = $this->pagination;
$this->_searchCriteria->query. = " profileTypePlaceholderTexxxxxt";
Yii::app()->search->SetLimits($this->pagination->offset, $this->pagination->limit);
Yii::app()->search->SetFieldWeights($this->_fieldWeights);
if ($this->_searchCriteria->query)
Yii::app()->search->setMatchMode(SPH_MATCH_ALL);
else
Yii::app()->search->setMatchMode(SPH_MATCH_FULLSCAN);
Yii::app()->search->setFieldWeights(array(
'primary_comp' => 100,
'premium' => 80,
'standard' => 60,
'free' => 40,
'comp' => 20,
'title' => 5,
'description' => 5,
));
//Yii::app()->search->SetSortMode(SPH_SORT_EXTENDED, '@weight DESC');
Yii::app()->search->SetSortMode(SPH_SORT_EXTENDED,'@weight DESC, random DESC');
foreach ($this->_searchCriteria->filters as $filter) {
if ($filter[0] == 'range')
Yii::app()->search->SetFilterFloatRange($filter[1], (float) $filter[2] + 0.01, (float) $filter[3]);
else
Yii::app()->search->SetFilter($filter[0], array($filter[1]));
}
$results = Yii::app()->search->Query($this->_searchCriteria->query, $this->_searchCriteria->from);
$this->_data = array();
$this->_keys = array();
$this->_itemCount = $results['total'];
$this->pagination->itemCount = $this->_itemCount;
if ($this->_itemCount) {
$this->_populateItems($results['matches']);
}
}






Честно говоря, поместить оба значения в один и тот же атрибут sphinx кажется проще всего. MVA идеально подходит для этого!
Можно было бы сделать пару способов, но просто...
sql_query = SELECT id,title, CONCAT_WS(',',typeId,altTypeId) AS typeids FROM ...
sql_attr_multi = uint typeids from field
тогда просто
->SetFilter('typeids', array(6));
находит результаты из ЛЮБОГО столбца.
В противном случае, если вы действительно хотите делать это только во время запроса, это что-то вроде
if ($filter[0] == 'typeid') {
Yii::app()->search->SetSelect("*, (typeid = {$filter[1]} OR altTypeId = {$filter[1]}) AS myfilter");
Yii::app()->search->SetFilter('myfilter', array(1));
} else ...