安装Sphinx
網址:http://sphinxsearch.com/downloads/current/
點擊最新版下載
?
?
在linux系統中執行
輸入 wget 將剛才復制的鏈接在后面加上 wget http://sphinxsearch.com/filessphinx-2.2.11-release.tar.gz 回車,等待下載
或者將安裝包下載下來再上傳到linux系統中也可以
步驟:
下載:
wget http://sphinxsearch.com/filessphinx-2.2.11-release.tar.gz解壓:
tar zxvf wget sphinx-2.2.11-release.tar.gz進入文件夾:
cd sphinx-2.2.11-release編譯:
./configure --prefix=/usr/local/sphinx --with-mysql可能會報下面的錯誤:?
解決方法:
vi confifure#define?USE_LIBICONV?0?in?line?8179.
修改?configure?文件把?#define?USE_LIBICONV?0?最后的數值由1改為0
重新編譯。
最后顯示
表明已經安裝成功
cd /usr/local/sphinx/etc vi sphinx.conf.dist將sphinx.conf.dist文件中的參數修改成下面的
# # Sphinx configuration file sample # # WARNING! While this sample file mentions all available options, # it contains (very) short helper descriptions only. Please refer to # doc/sphinx.html for details. ############################################################################## ## data source definition #############################################################################source src1 {# data source type. mandatory, no default value# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbctype = mysql####################################################################### SQL settings (for 'mysql' and 'pgsql' types)###################################################################### some straightforward parameters for SQL source typessql_host = localhostsql_user = rootsql_pass = 2018sql_db = tpblogsql_port = 3306 # optional, default is 3306# UNIX socket name# optional, default is empty (reuse client library defaults)# usually '/var/lib/mysql/mysql.sock' on Linux# usually '/tmp/mysql.sock' on FreeBSD#sql_sock = /tmp/mysql.sock# MySQL specific client connection flags# optional, default is 0## mysql_connect_flags = 32 # enable compression# MySQL specific SSL certificate settings# optional, defaults are empty## mysql_ssl_cert = /etc/ssl/client-cert.pem# mysql_ssl_key = /etc/ssl/client-key.pem# mysql_ssl_ca = /etc/ssl/cacert.pem# MS SQL specific Windows authentication mode flag# MUST be in sync with charset_type index-level setting# optional, default is 0## mssql_winauth = 1 # use currently logged on user credentials# ODBC specific DSN (data source name)# mandatory for odbc source type, no default value## odbc_dsn = DBQ=C:\data;DefaultDir=C:\data;Driver={Microsoft Text Driver (*.txt; *.csv)};# sql_query = SELECT id, data FROM documents.csv# ODBC and MS SQL specific, per-column buffer sizes# optional, default is auto-detect## sql_column_buffers = content=12M, comments=1M# pre-query, executed before the main fetch query# multi-value, optional, default is empty list of queries#sql_query_pre = SET NAMES utf8sql_query_pre = SET SESSION query_cache_type=OFF# main document fetch query# mandatory, integer document ID field MUST be the first selected columnsql_query = select des,des as attr_des,keywords,keywords as attr_keywords,content,content as attr_content from tpblog_arcdata# joined/payload field fetch query# joined fields let you avoid (slow) JOIN and GROUP_CONCAT# payload fields let you attach custom per-keyword values (eg. for ranking)## syntax is FIELD-NAME 'from' ( 'query' | 'payload-query' ); QUERY# joined field QUERY should return 2 columns (docid, text)# payload field QUERY should return 3 columns (docid, keyword, weight)## REQUIRES that query results are in ascending document ID order!# multi-value, optional, default is empty list of queries## sql_joined_field = tags from query; SELECT docid, CONCAT('tag',tagid) FROM tags ORDER BY docid ASC# sql_joined_field = wtags from payload-query; SELECT docid, tag, tagweight FROM tags ORDER BY docid ASC# file based field declaration## content of this field is treated as a file name# and the file gets loaded and indexed in place of a field## max file size is limited by max_file_field_buffer indexer setting# file IO errors are non-fatal and get reported as warnings## sql_file_field = content_file_path# range query setup, query that must return min and max ID values# optional, default is empty## sql_query will need to reference $start and $end boundaries# if using ranged query:## sql_query = \# SELECT doc.id, doc.id AS group, doc.title, doc.data \# FROM documents doc \# WHERE id>=$start AND id<=$end## sql_query_range = SELECT MIN(id),MAX(id) FROM documents# range query step# optional, default is 1024## sql_range_step = 1000# unsigned integer attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# optional bit size can be specified, default is 32## sql_attr_uint = author_id# sql_attr_uint = forum_id:9 # 9 bits for forum_idsql_attr_uint = article_aid# boolean attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# equivalent to sql_attr_uint with 1-bit size## sql_attr_bool = is_deleted# bigint attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# declares a signed (unlike uint!) 64-bit attribute## sql_attr_bigint = my_bigint_id# UNIX timestamp attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# similar to integer, but can also be used in date functions## sql_attr_timestamp = posted_ts# sql_attr_timestamp = last_edited_ts# sql_attr_timestamp = date_added# floating point attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# values are stored in single precision, 32-bit IEEE 754 format## sql_attr_float = lat_radians# sql_attr_float = long_radians# multi-valued attribute (MVA) attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# MVA values are variable length lists of unsigned 32-bit integers## syntax is ATTR-TYPE ATTR-NAME 'from' SOURCE-TYPE [;QUERY] [;RANGE-QUERY]# ATTR-TYPE is 'uint' or 'timestamp'# SOURCE-TYPE is 'field', 'query', or 'ranged-query'# QUERY is SQL query used to fetch all ( docid, attrvalue ) pairs# RANGE-QUERY is SQL query used to fetch min and max ID values, similar to 'sql_query_range'## sql_attr_multi = uint tag from query; SELECT docid, tagid FROM tags# sql_attr_multi = uint tag from ranged-query; \# SELECT docid, tagid FROM tags WHERE id>=$start AND id<=$end; \# SELECT MIN(docid), MAX(docid) FROM tags# string attribute declaration# multi-value (an arbitrary number of these is allowed), optional# lets you store and retrieve strings#sql_attr_string = attr_dessql_attr_string = attr_keywordssql_attr_string = attr_content# JSON attribute declaration# multi-value (an arbitrary number of these is allowed), optional# lets you store a JSON document as an (in-memory) attribute for later use## sql_attr_json = properties# combined field plus attribute declaration (from a single column)# stores column as an attribute, but also indexes it as a full-text field## sql_field_string = author# post-query, executed on sql_query completion# optional, default is empty## sql_query_post =# post-index-query, executed on successful indexing completion# optional, default is empty# $maxid expands to max document ID actually fetched from DB## sql_query_post_index = REPLACE INTO counters ( id, val ) \# VALUES ( 'max_indexed_id', $maxid )# ranged query throttling, in milliseconds# optional, default is 0 which means no delay# enforces given delay before each query stepsql_ranged_throttle = 0# kill-list query, fetches the document IDs for kill-list# k-list will suppress matches from preceding indexes in the same query# optional, default is empty## sql_query_killlist = SELECT id FROM documents WHERE edited>=@last_reindex# columns to unpack on indexer side when indexing# multi-value, optional, default is empty list## unpack_zlib = zlib_column# unpack_mysqlcompress = compressed_column# unpack_mysqlcompress = compressed_column_2# maximum unpacked length allowed in MySQL COMPRESS() unpacker# optional, default is 16M## unpack_mysqlcompress_maxsize = 16M# hook command to run when SQL connection succeeds# optional, default value is empty (do nothing)## hook_connect = bash sql_connect.sh# hook command to run after (any) SQL range query# it may print out "minid maxid" (w/o quotes) to override the range# optional, default value is empty (do nothing)## hook_query_range = bash sql_query_range.sh# hook command to run on successful indexing completion# $maxid expands to max document ID actually fetched from DB# optional, default value is empty (do nothing)## hook_post_index = bash sql_post_index.sh $maxid####################################################################### xmlpipe2 settings###################################################################### type = xmlpipe# shell command to invoke xmlpipe stream producer# mandatory## xmlpipe_command = cat /usr/local/sphinx/var/test.xml# xmlpipe2 field declaration# multi-value, optional, default is empty## xmlpipe_field = subject# xmlpipe_field = content# xmlpipe2 attribute declaration# multi-value, optional, default is empty# all xmlpipe_attr_XXX options are fully similar to sql_attr_XXX# examples:## xmlpipe_attr_timestamp = published# xmlpipe_attr_uint = author_id# xmlpipe_attr_bool = is_enabled# xmlpipe_attr_float = latitude# xmlpipe_attr_bigint = guid# xmlpipe_attr_multi = tags# xmlpipe_attr_multi_64 = tags64# xmlpipe_attr_string = title# xmlpipe_attr_json = extra_data# xmlpipe_field_string = content# perform UTF-8 validation, and filter out incorrect codes# avoids XML parser choking on non-UTF-8 documents# optional, default is 0## xmlpipe_fixup_utf8 = 1 }# inherited source example # # all the parameters are copied from the parent source, # and may then be overridden in this source definition #source src1throttled : src1 #{ # sql_ranged_throttle = 100 #}############################################################################# ## index definition ############################################################################## local index example # # this is an index which is stored locally in the filesystem # # all indexing-time options (such as morphology and charsets) # are configured per local index index test1 {# index type# optional, default is 'plain'# known values are 'plain', 'distributed', and 'rt' (see samples below)# type = plain# document source(s) to index# multi-value, mandatory# document IDs must be globally unique across all sourcessource = src1# index files path and file name, without extension# mandatory, path must be writable, extensions will be auto-appendedpath = /usr/local/sphinx/var/data/test1# document attribute values (docinfo) storage mode# optional, default is 'extern'# known values are 'none', 'extern' and 'inline'docinfo = extern# dictionary type, 'crc' or 'keywords'# crc is faster to index when no substring/wildcards searches are needed# crc with substrings might be faster to search but is much slower to index# (because all substrings are pre-extracted as individual keywords)# keywords is much faster to index with substrings, and index is much (3-10x) smaller# keywords supports wildcards, crc does not, and never will# optional, default is 'keywords'dict = keywords# memory locking for cached data (.spa and .spi), to prevent swapping# optional, default is 0 (do not mlock)# requires searchd to be run from rootmlock = 0# a list of morphology preprocessors to apply# optional, default is empty## builtin preprocessors are 'none', 'stem_en', 'stem_ru', 'stem_enru',# 'soundex', and 'metaphone'; additional preprocessors available from# libstemmer are 'libstemmer_XXX', where XXX is algorithm code# (see libstemmer_c/libstemmer/modules.txt)## morphology = stem_en, stem_ru, soundex# morphology = libstemmer_german# morphology = libstemmer_svmorphology = none# minimum word length at which to enable stemming# optional, default is 1 (stem everything)## min_stemming_len = 1# stopword files list (space separated)# optional, default is empty# contents are plain text, charset_table and stemming are both applied## stopwords = /usr/local/sphinx/var/data/stopwords.txt# wordforms file, in "mapfrom > mapto" plain text format# optional, default is empty## wordforms = /usr/local/sphinx/var/data/wordforms.txt# tokenizing exceptions file# optional, default is empty## plain text, case sensitive, space insensitive in map-from part# one "Map Several Words => ToASingleOne" entry per line## exceptions = /usr/local/sphinx/var/data/exceptions.txt# embedded file size limit# optional, default is 16K## exceptions, wordforms, and stopwords files smaller than this limit# are stored in the index; otherwise, their paths and sizes are stored## embedded_limit = 16K# minimum indexed word length# default is 1 (index everything)min_word_len = 1# ignored characters list# optional, default value is empty## ignore_chars = U+00AD# minimum word prefix length to index# optional, default is 0 (do not index prefixes)## min_prefix_len = 0# minimum word infix length to index# optional, default is 0 (do not index infixes)## min_infix_len = 0# maximum substring (prefix or infix) length to index# optional, default is 0 (do not limit substring length)## max_substring_len = 8# list of fields to limit prefix/infix indexing to# optional, default value is empty (index all fields in prefix/infix mode)## prefix_fields = filename# infix_fields = url, domain# expand keywords with exact forms and/or stars when searching fit indexes# search-time only, does not affect indexing, can be 0 or 1# optional, default is 0 (do not expand keywords)## expand_keywords = 1# n-gram length to index, for CJK indexing# only supports 0 and 1 for now, other lengths to be implemented# optional, default is 0 (disable n-grams)#ngram_len = 1# n-gram characters list, for CJK indexing# optional, default is empty#ngram_chars = U+3000..U+2FA1F# phrase boundary characters list# optional, default is empty## phrase_boundary = ., ?, !, U+2026 # horizontal ellipsis# phrase boundary word position increment# optional, default is 0## phrase_boundary_step = 100# blended characters list# blended chars are indexed both as separators and valid characters# for instance, AT&T will results in 3 tokens ("at", "t", and "at&t")# optional, default is empty## blend_chars = +, &, U+23# blended token indexing mode# a comma separated list of blended token indexing variants# known variants are trim_none, trim_head, trim_tail, trim_both, skip_pure# optional, default is trim_none## blend_mode = trim_tail, skip_pure# whether to strip HTML tags from incoming documents# known values are 0 (do not strip) and 1 (do strip)# optional, default is 0html_strip = 0# what HTML attributes to index if stripping HTML# optional, default is empty (do not index anything)## html_index_attrs = img=alt,title; a=title;# what HTML elements contents to strip# optional, default is empty (do not strip element contents)## html_remove_elements = style, script# whether to preopen index data files on startup# optional, default is 0 (do not preopen), searchd-only## preopen = 1# whether to enable in-place inversion (2x less disk, 90-95% speed)# optional, default is 0 (use separate temporary files), indexer-only## inplace_enable = 1# in-place fine-tuning options# optional, defaults are listed below## inplace_hit_gap = 0 # preallocated hitlist gap size# inplace_docinfo_gap = 0 # preallocated docinfo gap size# inplace_reloc_factor = 0.1 # relocation buffer size within arena# inplace_write_factor = 0.1 # write buffer size within arena# whether to index original keywords along with stemmed versions# enables "=exactform" operator to work# optional, default is 0## index_exact_words = 1# position increment on overshort (less that min_word_len) words# optional, allowed values are 0 and 1, default is 1## overshort_step = 1# position increment on stopword# optional, allowed values are 0 and 1, default is 1## stopword_step = 1# hitless words list# positions for these keywords will not be stored in the index# optional, allowed values are 'all', or a list file name## hitless_words = all# hitless_words = hitless.txt# detect and index sentence and paragraph boundaries# required for the SENTENCE and PARAGRAPH operators to work# optional, allowed values are 0 and 1, default is 0## index_sp = 1# index zones, delimited by HTML/XML tags# a comma separated list of tags and wildcards# required for the ZONE operator to work# optional, default is empty string (do not index zones)## index_zones = title, h*, th# index per-document and average per-index field lengths, in tokens# required for the BM25A(), BM25F() in expression ranker# optional, default is 0 (do not index field lenghts)## index_field_lengths = 1# regular expressions (regexps) to filter the fields and queries with# gets applied to data source fields when indexing# gets applied to search queries when searching# multi-value, optional, default is empty list of regexps## regexp_filter = \b(\d+)\" => \1inch# regexp_filter = (blue|red) => color# list of the words considered frequent with respect to bigram indexing# optional, default is empty## bigram_freq_words = the, a, i, you, my# bigram indexing mode# known values are none, all, first_freq, both_freq# option, default is none (do not index bigrams)## bigram_index = both_freq# snippet document file name prefix# preprended to file names when generating snippets using load_files option# WARNING, this is a prefix (not a path), trailing slash matters!# optional, default is empty## snippets_file_prefix = /mnt/mydocs/server1# whether to apply stopwords before or after stemming# optional, default is 0 (apply stopwords after stemming)## stopwords_unstemmed = 0# path to a global (cluster-wide) keyword IDFs file# optional, default is empty (use local IDFs)## global_idf = /usr/local/sphinx/var/global.idf }# inherited index example # # all the parameters are copied from the parent index, # and may then be overridden in this index definition #index test1stemmed : test1 #{ # path = /usr/local/sphinx/var/data/test1stemmed # morphology = stem_en #}# distributed index example # # this is a virtual index which can NOT be directly indexed, # and only contains references to other local and/or remote indexes #index dist1 #{# 'distributed' index type MUST be specified # type = distributed# local index to be searched# there can be many local indexes configured # local = test1 # local = test1stemmed# remote agent# multiple remote agents may be specified# syntax for TCP connections is 'hostname:port:index1,[index2[,...]]'# syntax for local UNIX connections is '/path/to/socket:index1,[index2[,...]]' # agent = localhost:9313:remote1 # agent = localhost:9314:remote2,remote3# agent = /var/run/searchd.sock:remote4# remote agent mirrors groups, aka mirrors, aka HA agents# defines 2 or more interchangeable mirrors for a given index part## agent = server3:9312 | server4:9312 :indexchunk2# agent = server3:9312:chunk2server3 | server4:9312:chunk2server4# agent = server3:chunk2server3 | server4:chunk2server4# agent = server21|server22|server23:chunk2# blackhole remote agent, for debugging/testing# network errors and search results will be ignored## agent_blackhole = testbox:9312:testindex1,testindex2# persistenly connected remote agent# reduces connect() pressure, requires that workers IS threads## agent_persistent = testbox:9312:testindex1,testindex2# remote agent connection timeout, milliseconds# optional, default is 1000 ms, ie. 1 sec # agent_connect_timeout = 1000# remote agent query timeout, milliseconds# optional, default is 3000 ms, ie. 3 sec # agent_query_timeout = 3000# HA mirror agent strategy# optional, defaults to ??? (random mirror)# know values are nodeads, noerrors, roundrobin, nodeadstm, noerrorstm## ha_strategy = nodeads# path to RLP context file# optional, defaut is empty## rlp_context = /usr/local/share/sphinx/rlp/rlp-context.xml #}# realtime index example # # you can run INSERT, REPLACE, and DELETE on this index on the fly # using MySQL protocol (see 'listen' directive below) #index rt #{# 'rt' index type must be specified to use RT index # type = rt# index files path and file name, without extension# mandatory, path must be writable, extensions will be auto-appended # path = /usr/local/sphinx/var/data/rt# RAM chunk size limit# RT index will keep at most this much data in RAM, then flush to disk# optional, default is 128M## rt_mem_limit = 512M# full-text field declaration# multi-value, mandatory # rt_field = title # rt_field = content# unsigned integer attribute declaration# multi-value (an arbitrary number of attributes is allowed), optional# declares an unsigned 32-bit attribute # rt_attr_uint = gid# RT indexes currently support the following attribute types:# uint, bigint, float, timestamp, string, mva, mva64, json## rt_attr_bigint = guid# rt_attr_float = gpa# rt_attr_timestamp = ts_added# rt_attr_string = author# rt_attr_multi = tags# rt_attr_multi_64 = tags64# rt_attr_json = extra_data #}############################################################################# ## indexer settings #############################################################################indexer {# memory limit, in bytes, kiloytes (16384K) or megabytes (256M)# optional, default is 128M, max is 2047M, recommended is 256M to 1024Mmem_limit = 128M# maximum IO calls per second (for I/O throttling)# optional, default is 0 (unlimited)## max_iops = 40# maximum IO call size, bytes (for I/O throttling)# optional, default is 0 (unlimited)## max_iosize = 1048576# maximum xmlpipe2 field length, bytes# optional, default is 2M## max_xmlpipe2_field = 4M# write buffer size, bytes# several (currently up to 4) buffers will be allocated# write buffers are allocated in addition to mem_limit# optional, default is 1M## write_buffer = 1M# maximum file field adaptive buffer size# optional, default is 8M, minimum is 1M## max_file_field_buffer = 32M# how to handle IO errors in file fields# known values are 'ignore_field', 'skip_document', and 'fail_index'# optional, default is 'ignore_field'## on_file_field_error = skip_document# lemmatizer cache size# improves the indexing time when the lemmatization is enabled# optional, default is 256K## lemmatizer_cache = 512M }############################################################################# ## searchd settings #############################################################################searchd {# [hostname:]port[:protocol], or /unix/socket/path to listen on# known protocols are 'sphinx' (SphinxAPI) and 'mysql41' (SphinxQL)## multi-value, multiple listen points are allowed# optional, defaults are 9312:sphinx and 9306:mysql41, as below## listen = 127.0.0.1# listen = 192.168.0.1:9312# listen = 9312# listen = /var/run/searchd.socklisten = 9312listen = 9306:mysql41# log file, searchd run info is logged here# optional, default is 'searchd.log'log = /usr/local/sphinx/var/log/searchd.log# query log file, all search queries are logged here# optional, default is empty (do not log queries)query_log = /usr/local/sphinx/var/log/query.log# client read timeout, seconds# optional, default is 5read_timeout = 5# request timeout, seconds# optional, default is 5 minutesclient_timeout = 300# maximum amount of children to fork (concurrent searches to run)# optional, default is 0 (unlimited)max_children = 30# maximum amount of persistent connections from this master to each agent host# optional, but necessary if you use agent_persistent. It is reasonable to set the value# as max_children, or less on the agent's hosts.persistent_connections_limit = 30# PID file, searchd process ID file name# mandatorypid_file = /usr/local/sphinx/var/log/searchd.pid# seamless rotate, prevents rotate stalls if precaching huge datasets# optional, default is 1seamless_rotate = 1# whether to forcibly preopen all indexes on startup# optional, default is 1 (preopen everything)preopen_indexes = 1# whether to unlink .old index copies on succesful rotation.# optional, default is 1 (do unlink)unlink_old = 1# attribute updates periodic flush timeout, seconds# updates will be automatically dumped to disk this frequently# optional, default is 0 (disable periodic flush)## attr_flush_period = 900# MVA updates pool size# shared between all instances of searchd, disables attr flushes!# optional, default size is 1Mmva_updates_pool = 1M# max allowed network packet size# limits both query packets from clients, and responses from agents# optional, default size is 8Mmax_packet_size = 8M# max allowed per-query filter count# optional, default is 256max_filters = 256# max allowed per-filter values count# optional, default is 4096max_filter_values = 4096# socket listen queue length# optional, default is 5## listen_backlog = 5# per-keyword read buffer size# optional, default is 256K## read_buffer = 256K# unhinted read size (currently used when reading hits)# optional, default is 32K## read_unhinted = 32K# max allowed per-batch query count (aka multi-query count)# optional, default is 32max_batch_queries = 32# max common subtree document cache size, per-query# optional, default is 0 (disable subtree optimization)## subtree_docs_cache = 4M# max common subtree hit cache size, per-query# optional, default is 0 (disable subtree optimization)## subtree_hits_cache = 8M# multi-processing mode (MPM)# known values are none, fork, prefork, and threads# threads is required for RT backend to work# optional, default is threadsworkers = threads # for RT to work# max threads to create for searching local parts of a distributed index# optional, default is 0, which means disable multi-threaded searching# should work with all MPMs (ie. does NOT require workers=threads)## dist_threads = 4# binlog files path; use empty string to disable binlog# optional, default is build-time configured data directory## binlog_path = # disable logging# binlog_path = /usr/local/sphinx/var/data # binlog.001 etc will be created there# binlog flush/sync mode# 0 means flush and sync every second# 1 means flush and sync every transaction# 2 means flush every transaction, sync every second# optional, default is 2## binlog_flush = 2# binlog per-file size limit# optional, default is 128M, 0 means no limit## binlog_max_log_size = 256M# per-thread stack size, only affects workers=threads mode# optional, default is 64K## thread_stack = 128K# per-keyword expansion limit (for dict=keywords prefix searches)# optional, default is 0 (no limit)## expansion_limit = 1000# RT RAM chunks flush period# optional, default is 0 (no periodic flush)## rt_flush_period = 900# query log file format# optional, known values are plain and sphinxql, default is plain## query_log_format = sphinxql# version string returned to MySQL network protocol clients# optional, default is empty (use Sphinx version)## mysql_version_string = 5.0.37# default server-wide collation# optional, default is libc_ci## collation_server = utf8_general_ci# server-wide locale for libc based collations# optional, default is C## collation_libc_locale = ru_RU.UTF-8# threaded server watchdog (only used in workers=threads mode)# optional, values are 0 and 1, default is 1 (watchdog on)## watchdog = 1# costs for max_predicted_time model, in (imaginary) nanoseconds# optional, default is "doc=64, hit=48, skip=2048, match=64"## predicted_time_costs = doc=64, hit=48, skip=2048, match=64# current SphinxQL state (uservars etc) serialization path# optional, default is none (do not serialize SphinxQL state)## sphinxql_state = sphinxvars.sql# maximum RT merge thread IO calls per second, and per-call IO size# useful for throttling (the background) OPTIMIZE INDEX impact# optional, default is 0 (unlimited)## rt_merge_iops = 40# rt_merge_maxiosize = 1M# interval between agent mirror pings, in milliseconds# 0 means disable pings# optional, default is 1000## ha_ping_interval = 0# agent mirror statistics window size, in seconds# stats older than the window size (karma) are retired# that is, they will not affect master choice of agents in any way# optional, default is 60 seconds## ha_period_karma = 60# delay between preforked children restarts on rotation, in milliseconds# optional, default is 0 (no delay)## prefork_rotation_throttle = 100# a prefix to prepend to the local file names when creating snippets# with load_files and/or load_files_scatter options# optional, default is empty## snippets_file_prefix = /mnt/common/server1/ }############################################################################# ## common settings ##############################################################################common #{# lemmatizer dictionaries base path# optional, defaut is /usr/local/share (see ./configure --datadir)## lemmatizer_base = /usr/local/share/sphinx/dicts# how to handle syntax errors in JSON attributes# known values are 'ignore_attr' and 'fail_index'# optional, default is 'ignore_attr'## on_json_attr_error = fail_index# whether to auto-convert numeric values from strings in JSON attributes# with auto-conversion, string value with actually numeric data# (as in {"key":"12345"}) gets stored as a number, rather than string# optional, allowed values are 0 and 1, default is 0 (do not convert)## json_autoconv_numbers = 1# whether and how to auto-convert key names in JSON attributes# known value is 'lowercase'# optional, default is unspecified (do nothing)## json_autoconv_keynames = lowercase# path to RLP root directory# optional, defaut is /usr/local/share (see ./configure --datadir)## rlp_root = /usr/local/share/sphinx/rlp# path to RLP environment file# optional, defaut is /usr/local/share/rlp-environment.xml (see ./configure --datadir)## rlp_environment = /usr/local/share/sphinx/rlp/rlp/etc/rlp-environment.xml# maximum total size of documents batched before processing them by the RLP# optional, default is 51200## rlp_max_batch_size = 100k# maximum number of documents batched before processing them by the RLP# optional, default is 50## rlp_max_batch_docs = 100# trusted plugin directory# optional, default is empty (disable UDFs)## plugin_dir = /usr/local/sphinx/lib#}# --eof--將注釋去掉的:
source src1 {type = mysqlsql_host = localhostsql_user = rootsql_pass = 2018sql_db = tpblogsql_sock = /tmp/mysql.socksql_query_pre = SET NAMES utf8sql_query_pre = SET SESSION query_cache_type=OFFsql_query = select id,des,des as attr_des,keywords,keywords as attr_keywords,content,content as attr_content from tpblog_arcdata #查詢的id是表的主鍵,一定要加上sql_attr_uint = article_aid #不能是主鍵(其他表的也不行)sql_attr_string = attr_dessql_attr_string = attr_keywordssql_attr_string = attr_contentsql_ranged_throttle = 0 } index test1 {source = src1path = /usr/local/sphinx/var/data/test1docinfo = externdict = keywordsmlock = 0morphology = nonemin_word_len = 1ngram_len = 1ngram_chars = U+3000..U+2FA1Fhtml_strip = 1 # 1 表示如果表中的數據是通過編輯器上傳的,表中會有標簽,如果搜索標簽會將數據全部搜索出來,改成 1 就搜索不出來了,默認是0 } indexer {mem_limit = 128M } searchd {listen = 9312listen = 9306:mysql41log = /usr/local/sphinx/var/log/searchd.logquery_log = /usr/local/sphinx/var/log/query.logread_timeout = 5client_timeout = 300max_children = 30persistent_connections_limit = 30pid_file = /usr/local/sphinx/var/log/searchd.pidseamless_rotate = 1preopen_indexes = 1unlink_old = 1mva_updates_pool = 1Mmax_packet_size = 8Mmax_filters = 256max_filter_values = 4096max_batch_queries = 32}建立索引:
cd /usr/local/sphinx/bin執行:
./indexer --all成功
開啟端口:
開啟9306和9316端口
將/home/wwwroot/default/www/sphinx-2.2.11-release/api中的sphinxapi.php和test.php復制到項目的根目錄下
在項目中運用
public function index() {$name=$_GET['name'];require ( "/home/wwwroot/default/www/sphinx-2.2.11-release/api/sphinxapi.php" );$cl = new \SphinxClient ();$q = $name; //要搜索的傳過來的關鍵詞$host = "localhost";$port = 9312;$index = 'test1';//索引$limit = 20;//限制輸出的條數$cl->SetServer ( $host, $port );$cl->SetConnectTimeout ( 1 );$cl->SetArrayResult ( true );if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );$res = $cl->Query ( $q, $index );p($res['matches']);}搜索的結果:
Array ([0] => Array([id] => 1[weight] => 2356[attrs] => Array([attr_des] => 我生在艱苦的年代,童年時,家里并不富裕,有時吃了上頓沒了下頓,哪還有錢買生日蛋糕啊,更不要說其它的生日禮物了,能吃上一碗熱騰騰的面條就很不錯了。記得有一年我生日,媽媽為我能吃上一[attr_keywords] => 老虎[attr_content] => 我有一只布老虎,是我很小的時候,媽媽送給我的生日禮物。我生在艱苦的年代,童年時,家里并不富裕,有時吃了上頓沒了下頓,哪還有錢買生日蛋糕啊,更不要說其它的生日禮物了,能吃上一碗熱騰騰的面條就很不錯了。記得有一年我生日,媽媽為我能吃上一頓面條,把家里僅有的兩碗小麥,用石磨磨成面粉,然后留下一碗面粉,其余的面粉搟成面條。吃飯時,我看見只有我的碗里全是面條,爸爸媽媽和兩個弟弟碗里大多是山芋,我趕緊把面條分點給爸爸媽媽和兩個弟弟,爸爸媽媽說什么也不要,只有兩個弟弟叫喳喳地:“我要我要!”就這樣我又快樂地過了一個生日。隨著我們漸漸長大,日子也好了很多。一家人過生日的時候,都能飽飽地吃上一頓面條。秋去冬來,我快十歲了,媽媽為趕在我的生日前,送我一只布老虎,坐在火爐旁一針一線,不知熬了多少個夜晚,才把一只栩栩如生的布老虎做好。這個生日最值得我懷念了,不但有面條吃,還有一個特別可愛的玩具,我高興極了,每天睡覺都抱在懷里。據說布老虎是一種古代就流傳的工藝品,它品種繁多,是驅邪避災、平安吉祥的象征,而且能保護財富。這或許是媽媽用心良苦的原因吧。))[1] => Array([id] => 7[weight] => 2353[attrs] => Array([attr_des] => 我沒有想到,在面臨全族滅絕的關健時刻,班羚們竟然能想出犧牲一半挽救一半的辦法來贏得家族的生存機會。我更沒想到,老班羚們會那么從容地面對死亡,即使自己被摔得粉身碎骨,也心甘情愿[attr_keywords] => 班羚 跳躍[attr_content] => 我曾見過一場異常悲壯的死亡,正是那次死亡深深震撼了我,我從此發誓不再傷害哪怕再微小的生命……那是在一次圍獵班羚的過程中。班羚又名青羊,形似家養山羊,擅長跳躍,每頭成年班羚重約30多公斤,性情溫馴,是獵人最喜歡的動物。 那次,我們狩獵隊嚴密堵截,把一群60多只羚羊逼到布朗山的斷命巖上,想把它們逼下巖去摔死,以免浪費子彈。 ))[2] => Array([id] => 5[weight] => 1401[attrs] => Array([attr_des] => 克拉倫斯非常難過,因為他的計劃完全失敗了。同時,他也非常生氣。因為當菲利克斯像一袋水泥一樣落下時,完全忘記了控制下落的速度,也完全忘記了“落下要更靈巧,而不是更重”的忠告。[attr_keywords] => 青蛙[attr_content] => 總是在夜闌人靜時,伴著徐徐柔風,鼓腮而鳴。遍布鄉村的空靈之音,仿佛要給馨香若醉的四野,傳送一縷辛勤耕耘的清涼。站在路邊,佇于村口,抑或走近待熟的莊稼,到處都可以領略到跳躍的韻律。一不小心,還會嚇你一個激靈。不過嚇過之后,它定會在不遠處,瞪著圓圓鼓鼓的眼睛,觀察你的反應。你動,他動。你不動,它不動。好像要把你的心思,引向隨風飄游的稻香。夏末初秋,少了些許驕陽似火的炎熱,這時節,青蛙便感覺最愜意。因為它們呱呱的叫聲,不會惹得人們心煩,反而會給日夜操勞的鄉親,帶來即將收割的喜悅。的確是這樣,每當忙碌了一天的人們,在歡聲笑語中吃完一頓并不豐盛但卻甜蜜的晚餐,便會打著飽飽的嗝,倒背著長滿老繭的大手,慢悠悠地行走在田間小道上,哼著雖然跑了調但自己卻依然滿意的山歌,一邊盡情地吮吸著瓜果的味道,一邊仔細地聆聽著蟲吟的美妙。那情形,如潑墨大師描繪的一幅田園山水。記得小時候,春暖花開,芳菲遍地,門前的小河嘩嘩地流淌著鄉村漸紅漸暖的熱情。逆流而上的小魚,搖著歡快的尾巴,偶爾把頭探出水面,吹一個調皮的氣泡,宛若要給萌動的季節,綴上一個傳神的標點。為什么不是呢?煩躁的季節,聽一曲蛙鳴,感受美妙的樂音,也是一種久違的禪境!))[3] => Array([id] => 3[weight] => 1387[attrs] => Array([attr_des] => 公園的某個角落有一群猴子,鐵柵欄外面是前來游玩的人。人看著猴子;猴子看著人。雖然都在看,想法定不同。人的思維能力舉世無雙自然不消說的,一看到某種東西對自己的心思,就美其名曰:欣賞。[attr_keywords] => 猴子[attr_content] => 公園的某個角落有一群猴子,鐵柵欄外面是前來游玩的人。人看著猴子;猴子看著人。雖然都在看,想法定不同。人的思維能力舉世無雙自然不消說的,一看到某種東西對自己的心思,就美其名曰:欣賞。由此而論抑或是猜想,人們一定以好奇的心理觀賞猴子,身心都很娛樂。那么猴子呢,就簡單的多了——它們可能什么都沒想,即便想也一定是自己的事情,不會對某個人特別感興趣。因為在猴子的眼里,人的模樣都差不多,就像咱看非洲黑人。有一點也許可以肯定:因為受到了某種來自人類的不公平待遇,他們私底下會認為:人,真不是東西!猴子的日子比人過得好。它們每天山上采食野果充饑,之后是公猴母猴談戀愛,大猴子帶著小猴子玩,之后就是攀援樹木山巖,盡情嬉戲玩耍。摘野果比武藝。比較而言,人就活得累多了。到底如何累法用不著多啰嗦,大家心中有數。假如我們隨便說一個人活得不如猴子,那被說的人一定十分的反感,以為是污蔑。人啊,大都以為自己的生存狀態優越于猴子,其實往深里想想,就知道我們人類實在是活得太累太累,那么多的不如意不自由,那么多的束縛欠灑脫。想想就叫人不寒而栗。上學被書包壓得喘不過氣來;畢業找不到合適的工作;談對象高不成低不就;工作了職務太低;上有老下有小顧頭不顧腚;到老了子女又不孝順,諸如此類的不如意你一點都不占,除非你是不是人間煙火的神仙。比比猴子,那么到底誰的生活狀態更值得肯定呢?任何的比較都須有標準,沒有標準的比較毫無意義。對于生命而言,唯一的標準就是活得幸福安康快樂無憂。這樣一比就不難判斷出到底誰的生活質量高了。從進化論角度看,人和猴子應是同一祖先,然而人和猴子永遠是并列關系而不是遞進關系。猴子要想變成人不可能,人也不會變成猴子,即使能夠也沒人去變,人們大都以為自己比猴子高級。事實到底如何?也用不著我來啰唆。我們人類曾經多么的自豪!將來將要多么的自豪!人類的進步常常是大自然的災難;將來也很可能就是自己的甚至殃及后代的災難。人類實在是進化的太快了。快得使我們忘記了森林曾是我們的故鄉,忘記了藍天碧水的無以倫比的重要性,我們住在鋼筋水泥隔就的空間里玩弄高科技,其目的就是不斷的與大自然拉開距離,讓更多的不起眼的小生命失去生存的可能。不要鄰居,拒絕朋友,人類的自作聰明已非一日,回歸自然的思考一直停留在辦公桌的表面,桌子頭上的舞蹈再跳一百年還是老樣子。大自然的忍耐力畢竟有限,還是小心為妙!小心無大錯!人,不能毫無顧忌。據說當年孟子的母親面對外出的兒子說過這樣一句話:小心,天下去得。對于亞圣母親的一句名言,我們大多數人的的確確是忽略了。那么猴子呢,它們的進步遠不會與人類同日而語,也許永遠是落后于我們的,然而它們無愧于這個星球,因為他們能夠與所有的他生物和平相處。在大力提倡和諧的當下,他們的生存狀態倒是值得稱道的。我們人類永遠也不要自以為是,永遠也不要自作聰明。如果我們單單從世界大和諧角度來看,人類一點不比猴子先進!我平生愛看也鬧,任何帶有娛樂性質的活動都愿意參加,可是有一種活動我很反感,那就是街頭上的耍猴子。一大群人圍著幾只猴子觀看,嘻嘻呵呵。那耍猴子的人手提一面鑼,當當當敲著,另一只手扯著一根或幾根繩子,那繩子皆是拴在猴子們的脖子上的,伴隨著鑼聲,猴子們被逼著按照主人的指令完成各類動作,圍觀人從猴子們的舉動中獲取樂趣。猴子舉動稍有不對就會慘遭鞭笞,人們的開心就建造在猴子的痛苦之上,有趣嗎?古人云,勿以惡小而為之,勿以善小而不為,己所不欲勿施于人,人們的良心雖然看不見摸不著,卻是實實在在存在的,并且須臾不可偏廢!我們人類一直就是以犧牲他類的幸福甚至生存換取自己的舒適的,這從善良的角度看是很不人道的。我們有時候會用悵惘的心境回望農耕時代的安寧與純凈;有時候免不了就想:不懂現代高科技的猴子的生活技巧比我們更接近生命的本質,是不是?))[4] => Array([id] => 8[weight] => 1387[attrs] => Array([attr_des] => 說實話,獅子林并不在我記憶的范疇。然而卻因為導游的講解,使我感到此園的和藹、親切。在腦中浮現的,只有我的現任班主任而已。您別奇怪我為和會想到班主任,其實原因頗多。[attr_keywords] => 獅子[attr_content] => 蘇州的獅子林,作為元代的古建筑,以及享有的“假山王國”的美譽,吸引著慕名而來的古今游人。我便是那茫茫人海中的一朵小小浪花。據說當年乾隆老爺子也來此游玩。游興未盡的萬歲,還下令在北京的圓明園、承德的避暑山莊內仿建了兩座獅子林。可見當年乾隆皇帝對獅子林的情有獨鐘。))[5] => Array([id] => 6[weight] => 1356[attrs] => Array([attr_des] => 虎毒不食子,母愛眾生同! 可是,與動物相比,我們的人性又有多少高尚之處呢?有時,即使不存惡意地進入動物的領域,都給動物造成傷害,更別說蓄意屠殺了。不久前,我聽到印度的一位同行講的一則有關犀牛的故事[attr_keywords] => 獵物虎[attr_content] => 我們常說,“可憐天下父母心”,那大概是專指人類而言,但同在藍天下的蕓蕓眾生,包括各種鳥獸蟲魚,哪一個沒有父母心、赤子情呢?可是我們人類居然視而不見,殺死動物的父母,喂養人類自己;侵占動物的生存空間,滿足自己的私欲,公道何在?良心何在?最近,我參加中央電視臺《視覺》欄目的一個節目,在演播室就此話題淋漓盡致地發了一番感慨,直說得善于言辭的主持人心事沉沉、無語凝噎。為什么?大概是這一樁樁、一件件有關鳥獸親情的可憐且可悲的故事,深深觸動了她的心。 一位獵人在追殺一只藏羚羊時,將羚羊逼向懸崖,使其走投無路。突然,這只藏羚羊不再奔跑,回頭面對獵人跪下了。“奇怪,動物還會求生?”獵人思忖著,但他并未因之而動惻隱之心,依然舉槍將近在咫尺的藏羚羊打死了。 拖著獵物回到住地,獵人解剖時發現,這只羚羊的腹中竟有一個胎兒。獵人怔住了:“這是一個即將生產的母親!難怪她跪下求饒,原來是為了保全孩子的性命!”獵人的鐵石心腸被感動了,“我干什么呀?真是禽獸不如!”終于,獵人丟掉獵槍,金盆洗手。)) )?
?
建立索引
/home/www/sphinx-3.1.1/bin/indexer -c /home/www/sphinx-3.1.1/bin/sphinx.conf --all
啟動sphinx?
/home/www/sphinx-3.1.1/bin/searchd -c /home/www/sphinx-3.1.1/bin/sphinx.conf
停止sphinx?
/home/www/sphinx-3.1.1/bin/searchd -c /home/www/sphinx-3.1.1/bin/sphinx.conf --stop
?
視頻地址:https://ke.qq.com/webcourse/index.html#cid=309238&term_id=100366592&taid=2108644259051510&vid=p1422t34kwo
?
?
?
?
?
總結
- 上一篇: Simscape Multiby学习笔记
- 下一篇: 驱动力来自哪里——献给迷茫的程序员