sphinx kill-list设置



官方文档:
*******************************************************************************************************************
11.1.16. sql_query_killlist:Kill-list查询

用于得到Kill-list的查询。可选选项,默认为空(不设定查询)。仅适用于SQL数据源(mysql, pgsql, mssql)。版本0.9.9-rc1引入.
这个查询返回的结果集应该只有一列,每行是一个文档ID。返回的这些文档ID将被存储在一个索引里。根据查询中提到的索引的顺序,一个索引的kill-list会抑制来自其他(顺序在其前面)索引的结果。这个设计的目的是要帮助用户实现在现有索引上的删除或者更新,而不用重建索引(甚至根本不用访问这个索引),尤其是为了结果解决“幽灵结果”问题。
让我们来分析一个实际的例子。假设我们有两个索引,‘main’和‘delta’。假设文档2、3和5在上一次重建索引‘main’的时候就被删除了,而文档7和文档11则被更新了(即他们的文字内容发生了变化)。假设在建立索引‘main’的时候,关键字‘test’在所有这些提到的文档中都出现了。而当我们建立索引‘delta’的时候文档7中也出现了关键字‘test’,但是文档11中不再有关键字‘test’了。现在我们重新建立索引‘delta’,然后以合适的顺序(较旧的排在较新的之前)对这两个索引进行检索:
$res = $cl->Query ( "test", "main delta" );
首先,我们要正确地处理删除的情况。结果集合不应该包含文档2、3或5。其次,我们也要避免出现幽灵结果。如果我们不做点什么,文档11就会出现在搜索结果中。因为它会被在‘main’中查到(但在‘delta’中查不到它),并出现在最终的结果集合中,除非我们做点什么防止这种情况的发生。
Kill-list,或者缩写成K-list就是我们要做的。附加在‘delta’索引上的Kill-list会屏蔽掉前面所有各索引中检索到的特定行,在这个例子中,也就是‘main’中的行。因此,想要得到预期的结果,我们应该将更新了的和删除了的文档ID都放进Kill-list。
示例:


sql_query_killlist = \
SELECT id FROM documents WHERE updated_ts>=@last_reindex UNION \
SELECT id FROM documents_deleted WHERE deleted_ts>=@last_reindex

*************************************************************************************************************


个人总结:
1.在delta index的源中要写sql_query_killlist
2.indexer --merge main delta --merge-dst-range deleted 0 0 --merge-killlists --rotate重建索引,合并索引
3.查询时一定要将旧的索引排在前面,在这里就是main在前,delta在后:search -i main -i delta xxx(这样后面delta中设置的sql_query_killlist才能起作用)

4.在用php的query接口时,也要注意给定的index的顺序,old在前,new在后,如果是*的话,一定要保证conf中声明的index顺序是旧前新后

5.如果想要用kill-list,那么一定不能只指定旧的main索引,因为sql_query_killlist并不是将关键字映射关系删除,而只是屏蔽,如果只指main,相当于delta中的sql_query_killlist并没有发挥作用,旧数据还是可以被查询到;必须指定main delta这样的索引顺序,才可以将delta中的sql_query_killlist效果产生在mian的结果集上。

6.--merge-killlists的作用只是生成一个ignore_list(if id in ignore_list)ignore,如果只有main作为指定范围,即使main的结果与delta的结果merge过,但是因为没有ignore_list作为过滤条件,旧的记录依然可以查询到;-i main -i delta这样才会将main的结果通过delta的ignore_list的过滤,因为在delta中设置了sql_query_killlist。


The kill-list is basically a list of "ignore this ids".

It does make sense. Is the delta index the last one specified in setup and query?
Otherwise it won't work.

Note that the kill list does not change the non-delta index, it simply provides a list of
ids that should be ignored on preceding indexes. Why do I say "preceding indexes"? Well,
consider this:

$cl->Query("some terms", "index1 index2withkilllist index3");

Any terms that would be excluded in the kill list will not affect index3 at all.

In your case, if the delta isn't the last index defined in the distributed index and
queried it'll fail.


你可能感兴趣的:(sql,list,kill,query,文档,merge)