coreseek实时索引更新之增量索引

coreseek实时索引更新有两种选择:

1.使用基于磁盘的索引,手动分区,然后定期重建较小的分区(被称为“增量”)。通过尽可能的减小重建部分的大小,可以将平均索引滞后时间降低到30~60秒.在0.9.x版本中,这是唯一可用的方法。在一个巨大的文档集上,这可能是最有效的一种方法

2.版本1.x(从版本1.10-beta开始)增加了实时索引(简写为Rt索引)的支持,用于及时更新全文数据。在RT索引上的更新,可以在1~2毫秒(0.001-0.002秒)内出现在搜索结果中。然而,RT实时索引在处理较大数据量的批量索引上效率并不高。

这篇我们只要是增量索引

基本思路是设置两个数据源和两个索引,对很少更新或根本不更新的数据建立主索引,而对新增文档建立增量索引

在配置文件中定义了主索引和增量索引之后,不能直接用indexer –config d:\coreseek\csft.conf –all,再添加数据到数据库中,再用indexer –config d:\coreseek\csft.confg main delta –rotate来弄(我居然这样弄了两次)。正确的步骤为:

1.创建主索引:indexer –cd:\coreseek\csft.conf --all

2.添加数据

3.再创建增量索引:indexer –cd:\coreseek\csft.conf delta --rotate

4.合并索引:indexer –cd:\coreseek\csft.conf --merge main delta –rotate(为了防止多个关键字指向同一个文档加上--merge-dst-range deleted 0 0)

增量配置文件如下:

[plain]  view plain copy
 
  1. #增量索引  
  2. source main  
  3. {  
  4.     type                    = mysql  
  5.     sql_host                = localhost  
  6.     sql_user                = root  
  7.     sql_pass                = 123456  
  8.     sql_db                  = hottopic  
  9.     sql_port                = 3306  
  10.     sql_query_pre           = SET NAMES utf8  
  11.     sql_query_pre       = replace into sph_counter select 1,max(id) from st_info  
  12.     sql_query_range     = select 1,max(id) from st_info  
  13.     sql_range_step          = 1000  
  14.   
  15.     sql_query               = SELECT id, pubDate, title, description,nav_id,rss_id FROM st_info where id>=$start and id <=$end and \  
  16.                 id <=(select max_doc_id from sph_counter where counter_id=1)  
  17.     sql_attr_uint           = nav_id            
  18.     sql_attr_uint       = rss_id  
  19.     sql_attr_timestamp      = pubDate   
  20. }  
  21.   
  22. source delta : main  
  23. {  
  24.     sql_query_pre           = SET NAMES utf8  
  25.     sql_query           = SELECT id, pubDate, title, description,nav_id,rss_id FROM st_info where id>=$start and id <=$end and \  
  26.                 id >(select max_doc_id from sph_counter where counter_id=1)  
  27.     sql_query_post_index    = replace into sph_counter select 1,max(id) from st_info  
  28. }  
  29.   
  30. #index定义  
  31. index main  
  32. {  
  33.     source              = main              
  34.     path                = D:/coreseek/coreseek-4.1-win32/var/data/mysqlInfoSPHMain   
  35.     docinfo             = extern  
  36.     mlock               = 0  
  37.     morphology          = none  
  38.     min_word_len        = 1  
  39.     html_strip          = 0  
  40.     stopwords       =  
  41.   
  42.     charset_dictpath    =  D:/coreseek/coreseek-4.1-win32/etc      
  43.     charset_type        = zh_cn.utf-8  
  44. }  
  45.   
  46. index delta : main  
  47. {  
  48.     source      = delta  
  49.     path                = D:/coreseek/coreseek-4.1-win32/var/data/mysqlInfoSPHDelta  
  50.      
  51. }  
  52.   
  53. #全局index定义  
  54. indexer  
  55. {  
  56.     mem_limit            = 128M  
  57. }  
  58.   
  59. #searchd服务定义  
  60. searchd  
  61. {  
  62.     listen          = 127.0.0.1:9312  
  63.     read_timeout        = 5  
  64.     max_children        = 30  
  65.     max_matches         = 1000  
  66.     seamless_rotate     = 0  
  67.     preopen_indexes     = 0  
  68.     unlink_old          = 1  
  69.     pid_file            = D:/coreseek/coreseek-4.1-win32/var/log/searchd_mysqlInfoSph.pid  
  70.     log             = D:/coreseek/coreseek-4.1-win32/var/log/searchd_mysqlInfoSph.log  
  71.     query_log           = D:/coreseek/coreseek-4.1-win32/var/log/query_mysqlInfoSph.log  
  72.     binlog_path         =            
  73.     compat_sphinxql_magics  = 0  
  74. }  


注意问题:如果我的主索引为50W条我前天建立的,我昨天增加了10W条的数据,并且建立了增量索引还和主索引合并了,我今天增加了10W的数据并且建立增量索引而且也和主索引合并了,在这两天内我是没有重新建立主索引的,问题来了:昨天是对10W数据进行建立,今天就是20W的数据建立,并且这20W数据中有10W数据其实在主索引中了,这个是非常可怕的?解决方案:

1.一天建立一次主索引

2.在不考虑重新建立主索引的时候,在添加增量索引的时候用sql_query_post_index来改变maxid值我是windows下面手动输入代码成功(不知道用脚本的时候会怎么样)

3.在不考虑重新建立主索引的时候,在合并索引的时候,用脚本链接数据库直接去修改(可以查看:http://banu.blog.163.com/blog/static/2314648201092911412539)

猜你喜欢

转载自qianxunniao.iteye.com/blog/1965855