问题
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