Coreseek Configuration and Incremental Index merge index

Source: Internet
Author: User
Guide: I am a novice php, the company's business is not cumbersome, but recently used to full-text search, thinking about using Sphinx.
Roughly divided into three parts, 1: installation; 2 configuration: 3 Call API. Here is the main point to configure and invoke the API. Installation steps I have previously written a single post can go to see, if not quite understand can go to the official website, the installation steps said very clearly, nonsense not much to say, start.
First, why use incremental index? In fact, I personally think that it is not necessary to use incremental indexing for a business with a small amount of data. It is OK to rebuild the index periodically. An incremental index is a separate index of what is added after the index that was last built, so that the amount of data is small, does not affect business processing, and then is indexed on a regular basis, and that the index must be rebuilt periodically in order to maintain data uniformity.
1, the ID of the last build index needs to be recorded, can be stored with a table.

CREATE Tabletbl_pre_coursevideo (Idint (one) NOT null default ' 0 ', maxidint (one) NOT null default ' 0 ',  PRIMARY KEY (ID)) Engine=innodb DEFAULT Charset=utf8;

2. Configuration files

SOURCE mysql{type = MySQL Sql_host = 127.0.0.1 Sql_user = root sql_p The 123456 sql_db = Test Sql_port = 3306 Sql_query_pre = Setnam ES UTF8 sql_query_pre = setsession query_cache_type=off #如果这里报错去mysql配置文件修改 sql_query_pre = Replaceint    O Tbl_pre_coursevideo SELECT1, MAX (ID) from Tbl_coursevideo #在刚才新建的表中将当前索引生成的最多id存起来, preparing for incremental indexing. Sql_query = Select Id,title,create_time, subtitle,content,type from Tbl_coursevideo WHERE ID <= (select m Axid from Tbl_pre_coursevideo where id=1) before #上面这条sql可以分为两部分WHERE, is the query for the data (depending on your business) where, is the filter for the maximum ID of the record just now Sql_at Tr_uint = id #从SQL读取到的值必须为整数 sql_attr_timestamp = create_time #从SQL读取到的值必须为整数, as time attribute sq l_field_string = Title #字符串字段 (full-text search, can return raw text information) sql_field_string = subtitle #字符串字段 (full-text search, can return the original text letter sql_field_string = Content #字符串字段 (Full-text search, can return raw text information)}source Increment:mysql{sql_query_pre = setnames utf8sql_query = SELECT id,titl E,create_time, Subtitle,content,type fromtbl_coursevideo where ID > (SELECT maxid from Tbl_pre_coursevideo where id=1) #这是增量索引的数据源sql. Consistent with the above, the only change is the where condition, where the query is greater than the ID of the last rebuild index, namely: the data just added} #index定义index mysql{Source = MySQL #对应的s            Ource name path =/usr/local/coreseek/var/data/mysql# Please modify the absolute path to actually use, for example:/usr/local/coreseek/var/... docinfo    = extern Mlock = 0morphology = None Min_word_len = 1html_strip = 0 #中文分词配置, for more information, see: Http://www.coreseek.cn/products-install/coreseek_mmseg/charset_dictpath =/usr/local/mmseg3/etc/# BSD, Linux settings,/symbol End #charset_dictpath = etc/#Windows环境下设置,/end of symbol, it is best to give absolute path, for example: c:/usr/local/ coreseek/etc/Charset_type = zh_cn.utf-8}index increment:mysql{source=increment path =/usr /local/coreseeK/var/data/increment Charset_dictpath =/usr/local/mmseg3/etc/charset_type = Zh_cn.utf-8} #全局index定义indexer {m        Em_limit = 128M} #searchd服务定义searchd {listen = 9312read_timeout = 5max_children = 30max_matches = 1000seamless_rotate = 0preopen_indexes = 0unlink_old = 1 pid_ File =/usr/local/coreseek/var/log/searchd_mysql.pid #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/. Log =/usr/local/ Coreseek/var/log/searchd_mysql.log #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/query_log =/usr/local/coreseek/v Ar/log/query_mysql.log #请修改为实际使用的绝对路径, for example:/usr/local/coreseek/var/...}

Use:
1, build the index (the command is my own installation environment path, the specific changes to their own)
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all#生成索引
A record is added to the Tbl_pre_coursevideo table. The maximum ID in your table of contents is stored.

2.
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf#开启后台进程

When searching for MySQL data sources, there is actually data.
3, incremental index (the premise of adding data to the content table)
/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf increment --rotate#执行完成以后会提示生成几条增量索引数据, which is the number of data bars you just added in the table of contents. At this point, you can actually test your incremental index success without cl->query ($keyword, ' increment '); When calling the API, you can use the incremental index to query what you just added
4. Merging indexes

Usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft.conf
–merge MySQL Increment–rotate

Cl->query (' Query the keyword ', ' mysql '); will be able to query out the newly added data, as well as the previous data.

5, in order to maintain the data unification, but also need to periodically new generation index

/usr/local/coreseek/bin/indexer-c/usr/local/coreseek/etc/csft.conf--all--rotate#--rotate does not affect server search when you can add this property

Two
1, call API, this is my own encapsulation, sphinxapi.php installation completed files have this class

Require ' sphinxapi.php '; class Sphinx {private$host= ' 127.0.0.1 ';p rivate$port=9312;private$cl;/*     * @desc Constructors  Initialize the Sphinx object     */public function __construct () {$this->cl =new sphinxclient (); $this->cl->setserver ($ This->host, $this->port); $this->cl->setconnecttimeout (1); $this->cl->setarrayresult (true); $ This->cl->setmatchmode (SPH_MATCH_EXTENDED2); $this->cl->setrankingmode (Sph_rank_wordcount);    } /     * * @desc Search     * @param $page  pages     * @param $pagesize  number     * @param $keyword  Search Keywords     * @ param $source Index Source     */public function Search ($keyword, $p, $pagesize) {$page = ($p-1) *10; $this->cl->setlimits ( $page, $pagesize); Paging $res= $this->cl->query ($keyword, $source); Sphinx Query    }  }

2. Scheduled Tasks
Yum Install crontab//Installation
CRONTAB-E//Open Edit
Then periodically perform incremental indexes, merge indexes, and build indexes from new

Live: If the merged index page was successful. But the data is always empty, so you just look at the configuration file.

Path            =/usr/local/coreseek/var/data/increment# The configuration here, whether the primary index is the same as the incremental index, increment is the file name of the index, which is in the Data folder.

That's it. If there is anything wrong, take a good look at this blog, including comments, which are some of the problems I encountered, all commented. If there is any do not understand the place can also give me a message, know no endless. Next time to tell you about which piece of participle.

'). addclass (' pre-numbering '). Hide ();                    $ (this). addclass (' has-numbering '). Parent (). append ($numbering);                    for (i = 1; i <= lines; i++) {                        $numbering. Append ($ ("). Text (i));                    };                    $numbering. FadeIn (1700);                });            
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.