002 # Minimal Sphinx configuration sample (clean, simple, functional) 003 # 004 source wp_posts 005 { 006 # data source type. mandatory, no default value 007 # known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc 008 type = mysql 009 ##################################################################### 010 ## SQL settings (for 'mysql' and 'pgsql' types) 011 ##################################################################### 012 013 # some straightforward parameters for SQL source types 014 sql_host = localhost 015 sql_user = root 016 sql_pass = root 017 sql_db = test 018 sql_port = 3306 # optional, default is 3306 019 020 #待索引数据获取前查询 021 sql_query_pre = SET NAMES utf8 022 sql_query_pre = SET SESSION query_cache_type=OFF 023 024 025 sql_query = selectID,post_content,post_title,post_name,guid,UNIX_TIMESTAMP(post_date) post_date \ 026 from wp_posts 027 028 #sql_field_string = post_title 029 #sql_field_string = post_content 030 sql_attr_timestamp = post_date 031 #sql_query_info = select * from wp_posts where ID=$id 032 } 033 index wp_posts 034 { 035 source = wp_posts 036 path = /home/coreseek/data/59n_posts 037 docinfo = extern 038 charset_dictpath = /usr/local/mmseg3/etc/ 039 charset_type = zh_cn.utf-8 040 } 041 042 ########增量索引,进行实时更新 043 044 source wp_posts_rt:wp_posts 045 { 046 sql_query = selectID,post_content,post_title,post_name,guid,UNIX_TIMESTAMP(post_date) \ 047 post_date \ 048 from wp_posts where UNIX_TIMESTAMP(post_modified) > UNIX_TIMESTAMP() - 300 049 } 050 index wp_posts_rt 051 { 052 source = wp_posts_rt 053 path = /home/coreseek/data/59n_posts_rt 054 docinfo = extern 055 charset_dictpath = /usr/local/mmseg3/etc/ 056 charset_type = zh_cn.utf-8 057 } 058 059 060 source wp_comment 061 { 062 type = mysql 063 sql_host = localhost 064 sql_user = root 065 sql_pass = root 066 sql_db = test 067 sql_port = 3306 # optional, default is 3306 068 #待索引数据获取前查询 069 sql_query_pre = SET NAMES utf8 070 sql_query_pre = SET SESSION query_cache_type=OFF 071 072 073 sql_query = selectcomment_ID,comment_post_ID,comment_author,comment_content,UNIX_TIMESTAMP(comment_date) comment_date from wp_comments 074 075 sql_attr_uint = comment_post_ID 076 #sql_field_string = comment_author 077 #sql_field_string = comment_content 078 079 sql_attr_timestamp = comment_date 080 #sql_query_info = select * from wp_comments where comment_ID=$id 081 } 082 083 084 085 index wp_comment 086 { 087 source = wp_comment 088 path = /home/coreseek/data/59n_comment 089 docinfo = extern 090 charset_dictpath = /usr/local/mmseg3/etc/ 091 charset_type = zh_cn.utf-8 092 } 093 094 ########增量索引,进行实时更新 095 096 source wp_comment_rt:wp_comment 097 { 098 sql_query = selectcomment_ID,comment_post_ID,comment_author,comment_content,UNIX_TIMESTAMP(comment_date) comment_date from wp_comments \ 099 where UNIX_TIMESTAMP(comment_date) > UNIX_TIMESTAMP() - 300 100 } 101 index wp_comment_rt 102 { 103 source = wp_comment_rt 104 path = /home/coreseek/data/59n_comment_rt 105 docinfo = extern 106 charset_dictpath = /usr/local/mmseg3/etc/ 107 charset_type = zh_cn.utf-8 108 } 109 110 indexer 111 { 112 mem_limit = 256M 113 } 114 115 116 searchd 117 { 118 listen = 9312 119 listen = 9306:mysql41 120 log = /usr/local/coreseek/var/log/searchd.log 121 query_log = /usr/local/coreseek/var/log/query.log 122 read_timeout = 5 123 max_children = 10 124 pid_file = /usr/local/coreseek/var/log/searchd.pid 125 max_matches = 1000 126 seamless_rotate = 1 127 preopen_indexes = 1 128 unlink_old = 1 129 workers = threads # for RT to work 130 } 进行首次索引 ./bin/indexer --all 使用crontab -e进行增量索引进行实时更新 */4 * * * * /usr/local/coreseek/bin/indexer --rotate wp_posts_rt wp_comment_rt */4 * * * * /usr/local/coreseek/bin/indexer --rotate --merge wp_posts wp_posts_rt */4 * * * * /usr/local/coreseek/bin/indexer --rotate --merge wp_comment wp_comment_rt 在PHP中使用sphinx扩展进行搜索. 1 $sp = new SphinxClient(); 2 $sp->setMatchMode(SPH_MATCH_ANY); 3 $result = $sp->query($name); 4 //$err 错误 5 $err = $sp->GetLastError(); 6 echo '<pre>'; 7 var_dump($result); 8 var_dump($err); 9 echo '</pre>';