天天看點

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 plaincopy

  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.     sql_query               = SELECT id, pubDate, title, description,nav_id,rss_id FROM st_info where id>=$start and id <=$end and \  
  15.                 id <=(select max_doc_id from sph_counter where counter_id=1)  
  16.     sql_attr_uint           = nav_id            
  17.     sql_attr_uint       = rss_id  
  18.     sql_attr_timestamp      = pubDate   
  19. }  
  20. source delta : main  
  21.     sql_query           = SELECT id, pubDate, title, description,nav_id,rss_id FROM st_info where id>=$start and id <=$end and \  
  22.                 id >(select max_doc_id from sph_counter where counter_id=1)  
  23.     sql_query_post_index    = replace into sph_counter select 1,max(id) from st_info  
  24. #index定義  
  25. index main  
  26.     source              = main              
  27.     path                = D:/coreseek/coreseek-4.1-win32/var/data/mysqlInfoSPHMain   
  28.     docinfo             = extern  
  29.     mlock               = 0  
  30.     morphology          = none  
  31.     min_word_len        = 1  
  32.     html_strip          = 0  
  33.     stopwords       =  
  34.     charset_dictpath    =  D:/coreseek/coreseek-4.1-win32/etc      
  35.     charset_type        = zh_cn.utf-8  
  36. index delta : main  
  37.     source      = delta  
  38.     path                = D:/coreseek/coreseek-4.1-win32/var/data/mysqlInfoSPHDelta  
  39. #全局index定義  
  40. indexer  
  41.     mem_limit            = 128M  
  42. #searchd服務定義  
  43. searchd  
  44.     listen          = 127.0.0.1:9312  
  45.     read_timeout        = 5  
  46.     max_children        = 30  
  47.     max_matches         = 1000  
  48.     seamless_rotate     = 0  
  49.     preopen_indexes     = 0  
  50.     unlink_old          = 1  
  51.     pid_file            = D:/coreseek/coreseek-4.1-win32/var/log/searchd_mysqlInfoSph.pid  
  52.     log             = D:/coreseek/coreseek-4.1-win32/var/log/searchd_mysqlInfoSph.log  
  53.     query_log           = D:/coreseek/coreseek-4.1-win32/var/log/query_mysqlInfoSph.log  
  54.     binlog_path         =            
  55.     compat_sphinxql_magics  = 0  

注意問題:如果我的主索引為50W條我前天建立的,我昨天增加了10W條的資料,并且建立了增量索引還和主索引合并了,我今天增加了10W的資料并且建立增量索引而且也和主索引合并了,在這兩天内我是沒有重建立立主索引的,問題來了:昨天是對10W資料進行建立,今天就是20W的資料建立,并且這20W資料中有10W資料其實在主索引中了,這個是非常可怕的?解決方案:

繼續閱讀