【发布时间】:2018-11-02 10:47:31
【问题描述】:
有一种方法可以避免在 Sphinx 中搜索时,由于在两个索引(主索引和增量索引)中都存在 id 重复的结果?我知道我可以通过运行两个索引的合并来解决这个问题,但我想知道是否有另一种方法可以避免合并,因为服务器每次都运行它可能会很昂贵。
【问题讨论】:
标签: php full-text-search sphinx
有一种方法可以避免在 Sphinx 中搜索时,由于在两个索引(主索引和增量索引)中都存在 id 重复的结果?我知道我可以通过运行两个索引的合并来解决这个问题,但我想知道是否有另一种方法可以避免合并,因为服务器每次都运行它可能会很昂贵。
【问题讨论】:
标签: php full-text-search sphinx
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),定义杀戮列表的命令和行为可能会有所不同。
【讨论】: