PHP search optimization sphinx combat

Environment: win7 64 wamp

After decompressing the sphinx installation package, the resume structure is as follows. Note, the conf directory is my config file directory

In the conf directory, resume the newdefend.conf file, the configuration content is as follows

# configure the data source
source domain_src
{
    type            = mysql
    sql_host        = 192.168.185.210
    sql_user        = root
    sql_pass        =
    sql_db            = mydb
    sql_port        = 3306    
    
    sql_ranged_throttle    = 0
    sql_query_pre        = SET NAMES utf8
    # sql_query_pre       = SET SESSION query_cache_type=OFF
    sql_query_pre          = REPLACE INTO sph_counter SELECT 1 , MAX(id) FROM domain 
   # Note that in this place, at least the respective fields must not be defined as sql_attr_***, it seems that a field needs to be a full-text index or something. Anyway, it is right to query one more field. Or define a sql_field_string or 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 } # Configure incremental data source source delta_domain_src:domain_src{ sql_ranged_throttle = 100 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 index domain_suggest { source = domain_src path = D:/sphinx/data/domain_suggest charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F docinfo = extern dict = keywords mlock = 0 morphology = none min_word_len = 1 ngram_len = 1 ngram_chars = U+3000..U+2FA1F html_strip = 0 } # Incremental index index delta_domain_suggest:domain_suggest { source = delta_domain_src path = D:/sphinx/data/delta_domain_suggest } indexer { mem_limit = 128M } # Configure Sphinx server information searchd { listen = 9312 listen = 9306:mysql41 log = D:/sphinx/log/searchd.log query_log = D:/sphinx/log/query.log read_timeout = 5 client_timeout = 300 max_children = 30 persistent_connections_limit = 30 pid_file = D:/sphinx/log/searchd.pid preopen_indexes = 1 unlink_old = 1 mva_updates_pool = 1M max_packet_size = 8M max_filters = 256 max_filter_values = 4096 max_batch_queries = 32 workers = threads # Start the searchd service under windows and you must comment out this   # seamless_rotate = 1 # When the sphinx service is started, several log files will be generated, and the configuration file will be generated here. By default, it will be generated in the same directory as searchd.exe binlog_path = D:/sphinx/log/ }

Define a script "sphinx restart.bat" that starts sphinx. The content of the script is as follows, double-click to start

@echo off

:: stop sphinx service
d:/sphinx/bin/searchd --stop

:: Build 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

Startup success interface

test code

$keyword = '' ;
 $sphinx = new SphinxClient;
 $sphinx ->setServer("localhost", 9312 );
 $sphinx ->setMatchMode(SPH_MATCH_ALL);    // The matching mode ANY is automatic keyword splitting, and ALL is not splitting Word matching (exact match) 
$sphinx ->SetArrayResult ( true );     // The returned result set is an array 
$result = $sphinx ->query( $keyword ,"domain_suggest delta_domain_suggest");     // Asterisks are all index sources 
$ count = $result ['total'];         // Number of results found 
$time = $result ['time'];            // time 
$arr = $result ['matches'];         // result set 
$id ='' ;
 foreach ( $arr  as  $i => $val ){
     $id .= $arr [ $i ][' id'].',' ;
}
$id = substr ( $id ,0,-1);             // The id string of the result set

echo $id;

operation result

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324773718&siteId=291194637