我正在查询一个包含用户创建的记录的索引。由于我的应用程序可以有多种类型的用户,因此该表具有 CreatedByType 和 CreatedById。
我想排除由某个特定用户创建的结果。
// Exclude $userId from the results
$this->Client->SetFilter('CreatedById', $userId, true);
但是,这显然会排除 id 为 $userId
的所有用户类型的结果。同样:
// Exclude $userId from the results
$this->Client->SetFilter('CreatedByType', $userType, true);
将排除 $userType
型所有用户的结果。
如何将两个属性组合到一个约束中并对其进行AND
查询?
谢谢
可以计算虚拟组合属性,并对其进行过滤。
$this->Client->setSelect("*, IF(CreatedById=$userId,1,0)+IF(CreatedByType=$userType,1,0) as myfilter");
$this->Client->setFilterRange('myfilter',0,1);
(0 表示不匹配,1 表示一个匹配,2 表示两个匹配。因此,设置过滤器范围排除了两者匹配的文档!