【问题标题】:Sphinx - Duplicated results when searchingSphinx - 搜索时重复的结果
【发布时间】:2018-11-02 10:47:31
【问题描述】:

有一种方法可以避免在 Sphinx 中搜索时,由于在两个索引(主索引和增量索引)中都存在 id 重复的结果?我知道我可以通过运行两个索引的合并来解决这个问题,但我想知道是否有另一种方法可以避免合并,因为服务器每次都运行它可能会很昂贵。

【问题讨论】:

    标签: php full-text-search sphinx


    【解决方案1】:

    1) 只需将两个索引作为本地或代理创建分布式索引,或仅在搜索查询中使用逗号,即可同时针对这两个索引运行查询,例如:

    mysql> select * from idx_min;
    +------+--------------------------------------------------------------+------+
    | id   | doc                                                          | a    |
    +------+--------------------------------------------------------------+------+
    |    1 | dog cat parrot juice apple mandarine juice juice apple juice |  123 |
    |    2 | dog cat juice apple apple juice                              |  123 |
    +------+--------------------------------------------------------------+------+
    2 rows in set (0.01 sec)
    
    mysql> select * from idx_min2;
    +------+--------------------------------------------------------------+------+
    | id   | doc                                                          | a    |
    +------+--------------------------------------------------------------+------+
    |    1 | dog cat parrot juice apple mandarine juice juice apple juice |  123 |
    |    2 | dog cat juice apple apple juice                              |  123 |
    +------+--------------------------------------------------------------+------+
    2 rows in set (0.00 sec)
    

    即我们可以看到两个索引都有 id 为 1 和 2 的文档。但是:

    mysql> select * from idx_min, idx_min2;
    +------+--------------------------------------------------------------+------+
    | id   | doc                                                          | a    |
    +------+--------------------------------------------------------------+------+
    |    1 | dog cat parrot juice apple mandarine juice juice apple juice |  123 |
    |    2 | dog cat juice apple apple juice                              |  123 |
    +------+--------------------------------------------------------------+------+
    2 rows in set (0.00 sec)
    

    为我们提供删除了重复项的文档。

    2) 要使重复数据删除的方式更加可控,您可以使用 kill-lists。 Kill-list 是分配给索引的 ID 列表,表示应从任何先前的索引中删除这些 ID。根据您使用的版本(Sphinx 2 / Manticore / Sphinx 3),定义杀戮列表的命令和行为可能会有所不同。

    【讨论】:

    • 我已经在使用第一个解决方案,但是如果我搜索第一个索引和第二个索引中的一些内容(有一些更改),我会收到结果。例如,如果在您的示例中,第一行的 doc 列包含“hello world”并且我搜索该词,我会收到该结果,即使同一行在具有不同值的第二个索引内也是如此。
    • 相反,我看到的是第二种解决方案,也许就是我正在搜索的内容
    • 使用 Kill-list 可以按预期工作,非常感谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 2012-04-12
    • 2013-03-27
    相关资源
    最近更新 更多