Environment: Win7 Wamp
After unpacking the Sphinx installation package, resume the following structure. Note that the Conf directory is my profile directory
In the Conf directory, resume newdefend.conf file, configuration content as follows
# Configure DataSource source domain_src{type=MySQL sql_host=192.168.185.210Sql_user=Root Sql_pass=sql_db=mydb Sql_port=3306Sql_ranged_throttle=0Sql_query_pre=SET NAMES UTF8 # sql_query_pre= SET SESSION query_cache_type=OFF Sql_query_pre= REPLACE into Sph_counter SELECT1, MAX (ID) from domain
# Note This place, at least to have the respective fields not defined as sql_attr_***, as if there is a need to have a field that is full-text indexed or something. Anyway, it's right to query a field more than one. Or define a sql_field_string can also sql_query=SELECT id,uid,type,package_level,ct,domain from domain WHERE ID<= (SELECT max_id from sph_counter WHERE counter_id =1) Sql_attr_uint=UID Sql_attr_uint=type Sql_attr_uint=Package_level # sql_field_string=CT Sql_attr_timestamp=ct}# Configuring the incremental data source delta_domain_src:domain_src{Sql_ranged_throttle= -Sql_query_pre=SET NAMES UTF8 # sql_query_pre= SET SESSION query_cache_type=OFF sql_query=SELECT id,uid,type,package_level,ct,domain from domain WHERE ID> (SELECT max_id from sph_counter WHERE counter_id =1)} # index domain_suggest{source=domain_src Path= d:/sphinx/data/domain_suggest charset_table=0..9A.. Z->a. Z, _, a.. Z, u+410.. u+42f->u+430.. u+44f, u+430.. u+44F DocInfo=externDict=keywords Mlock=0morphology=None Min_word_len=1Ngram_len=1Ngram_chars= u+ the.. u+2fa1f Html_strip=0}# Incremental Indexes index delta_domain_suggest:domain_suggest {source=delta_domain_src Path= d:/sphinx/data/delta_domain_suggest}indexer{Mem_limit=128m}# Configuring Sphinx Server Information searchd{Listen=9312Listen=9306: mysql41 Log= d:/sphinx/log/Searchd.log Query_log= d:/sphinx/log/Query.log read_timeout=5Client_timeout= -Max_children= -Persistent_connections_limit= -Pid_file= d:/sphinx/log/searchd.pid preopen_indexes=1Unlink_old=1Mva_updates_pool=1M max_packet_size=8M max_filters= themax_filter_values=4096max_batch_queries= +Workers=Threads # Start SEARCHD service under Windows Be sure to comment out this # seamless_rotate=1# When the Sphinx service is turned on, several log files are generated, where the configuration file generates the directory. The default is generated in the Searchd.exe sibling directory Binlog_path= d:/sphinx/log/}
Define a script that starts Sphinx "Sphinx reboot. Bat". The script content is as follows, double click Start
@echo off:: Stop Sphinx Service D:/sphinx/bin/searchd-stop:: Create all indexes in the configuration file (you can also build an index) d:/sphinx/bin/indexer -C d:/sphinx/conf/newdefend.conf--all:: Start Sphinx Service D:/sphinx/bin/searchd-c d:/sphinx/conf/ newdefend.conf:: Window do not close pause
Launch successful interface
Test code
$keyword= ' ';$sphinx=Newsphinxclient;$sphinx->setserver ("localhost", 9312);$sphinx->setmatchmode (Sph_match_all);//match mode Any for keyword auto-split, all for non-split word matching (exact match)$sphinx->setarrayresult (true);//The result set returned is an array$result=$sphinx->query ($keyword, "Domain_suggest delta_domain_suggest");//asterisk for all index sources$count=$result[' Total '];//number of result bars found$time=$result[' Time '];//Time Consuming$arr=$result[' matches '];//result set$id= ' ';foreach($arr as $i=$val){ $id.=$arr[$i[' ID ']. ', ';}$id=substr($id, 0,-1);//ID string for the result setEcho $id;
Run results
PHP Search Optimization Sphinx Combat