【问题标题】:Sphinx - exclude filter by multiple attributesSphinx - 按多个属性排除过滤器
【发布时间】:2012-12-05 23:43:07
【问题描述】:

我正在查询包含用户创建的记录的索引。由于我的应用程序可以有多种类型的用户,因此该表具有 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 查询?

谢谢

【问题讨论】:

    标签: php indexing sphinx


    【解决方案1】:

    可以计算一个虚拟组合属性,并对其进行过滤。

    $this->Client->setSelect("*, IF(CreatedById=$userId,1,0)+IF(CreatedByType=$userType,1,0) as myfilter");
    $this->Client->setFilterRange('myfilter',0,1);
    

    (0 表示不匹配,1 表示一个匹配,2 表示两个都匹配。所以 setfilterrange 排除了两个都匹配的文档!)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      相关资源
      最近更新 更多