AND multiple values of a filter in sphinx

拈花ヽ惹草 提交于 2019-12-23 04:33:18

问题


I have an attribute in my sphinx index tag_id and now I want to fetch all record that have tag_id 10 and 11

When I do $sphinxClient->setFilter('tag_id', array(10,11)) it fetches all have tag_id 10 or 11 Is it possible to AND both values rather than OR?


回答1:


$sphinxClient->setFilter('tag_id', array(10));
$sphinxClient->setFilter('tag_id', array(11));

Multiple calls to setFilter are ANDed :)




回答2:


Why would two different values return result with AND??

It's like

WHERE id = 1 AND id = 2

WHICH will never be possible. Can you tell us the scenerio you're trying to work at?




回答3:


In my case Barry's answer didn't worked.

I have check what im filtering - an array or not array. By specification http://php.net/manual/en/sphinxclient.setfilter.php for values you need: 'Plain array of integer values.'

if( !empty( $filters['user_id'] ) ) 
{
  if( is_array( $filters['user_id'] ) )
  {
    $this->sphinx->setFilter( 'user_id', $filters['user_id'] );
  }
  else
  {
    $this->sphinx->setFilter( 'user_id', array( (int) $filters['user_id'] ) );
  }
} 


来源:https://stackoverflow.com/questions/10090158/and-multiple-values-of-a-filter-in-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!