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- #增量索引
- source main
- {
- type = mysql
- sql_host = localhost
- sql_user = root
- sql_pass = 123456
- sql_db = hottopic
- sql_port = 3306
- sql_query_pre = SET NAMES utf8
- sql_query_pre = replace into sph_counter select 1,max(id) from st_info
- sql_query_range = select 1,max(id) from st_info
- sql_range_step = 1000
- sql_query = SELECT id, pubDate, title, description,nav_id,rss_id FROM st_info where id>=$start and id <=$end and \
- id <=(select max_doc_id from sph_counter where counter_id=1)
- sql_attr_uint = nav_id
- sql_attr_uint = rss_id
- sql_attr_timestamp = pubDate
- }
- source delta : main
- sql_query = SELECT id, pubDate, title, description,nav_id,rss_id FROM st_info where id>=$start and id <=$end and \
- id >(select max_doc_id from sph_counter where counter_id=1)
- sql_query_post_index = replace into sph_counter select 1,max(id) from st_info
- #index定義
- index main
- source = main
- path = D:/coreseek/coreseek-4.1-win32/var/data/mysqlInfoSPHMain
- docinfo = extern
- mlock = 0
- morphology = none
- min_word_len = 1
- html_strip = 0
- stopwords =
- charset_dictpath = D:/coreseek/coreseek-4.1-win32/etc
- charset_type = zh_cn.utf-8
- index delta : main
- source = delta
- path = D:/coreseek/coreseek-4.1-win32/var/data/mysqlInfoSPHDelta
- #全局index定義
- indexer
- mem_limit = 128M
- #searchd服務定義
- searchd
- listen = 127.0.0.1:9312
- read_timeout = 5
- max_children = 30
- max_matches = 1000
- seamless_rotate = 0
- preopen_indexes = 0
- unlink_old = 1
- pid_file = D:/coreseek/coreseek-4.1-win32/var/log/searchd_mysqlInfoSph.pid
- log = D:/coreseek/coreseek-4.1-win32/var/log/searchd_mysqlInfoSph.log
- query_log = D:/coreseek/coreseek-4.1-win32/var/log/query_mysqlInfoSph.log
- binlog_path =
- compat_sphinxql_magics = 0
注意問題:如果我的主索引為50W條我前天建立的,我昨天增加了10W條的資料,并且建立了增量索引還和主索引合并了,我今天增加了10W的資料并且建立增量索引而且也和主索引合并了,在這兩天内我是沒有重建立立主索引的,問題來了:昨天是對10W資料進行建立,今天就是20W的資料建立,并且這20W資料中有10W資料其實在主索引中了,這個是非常可怕的?解決方案: