[转]php sphinx 高效率搜索引擎搭建

原文地址:http://blog.csdn.net/adparking/article/details/7207119

 

1.下载PHP客户端安装:

http://pecl.php.net/package/sphinx

 

vim sphinxclient.c
找到
void sock_close ( int sock );
改为
static void sock_close ( int sock );

 


 php.ini加扩展,客户端安装完毕

2.安装sphinx,前提你已经安装mysql且安装了mysql-devel重源码安装mysql

mysql-devel都已经安装,yum安装的运行
yum -y install mysql-devel

下载sphinx2.0.1地址:  

http://sphinxsearch.com/downloads/

 

tar -xvzf sphinx-2.0.1-beta.tar.gz
cd sphinx-2.0.1-beta
./configure –prefix=/usr/local/sphinx –with-mysql –with-iconv

 

备注:64位增加参数 –enable-id64


make && make install cd /usr/local/sphinx/etc/ cp sphinx.conf.dist sphinx.conf

 

 

  1. #  
  2. # Sphinx configuration file sample  
  3. #  
  4. # WARNING! While this sample file mentions all available options,  
  5. # it contains (very) short helper descriptions only. Please refer to  
  6. # doc/sphinx.html for details.  
  7. #  
  8.   
  9. #############################################################################  
  10. ## data source definition  
  11. #############################################################################  
  12.   
  13. source src1  
  14. {  
  15.     # data source type. mandatory, no default value  
  16.     # known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc  
  17.     type            = mysql  
  18.   
  19.     #####################################################################  
  20.     ## SQL settings (for ’mysql’ and ’pgsql’ types)  
  21.     #####################################################################  
  22.   
  23.     # some straightforward parameters for SQL source types  
  24.     sql_host        = localhost  
  25.     sql_user        = root  
  26.     sql_pass        = ******   
  27.     sql_db            = ******  
  28.     sql_port        = 3306    # optional, default is 3306  
  29.   
  30.     # UNIX socket name  
  31.     # optional, default is empty (reuse client library defaults)  
  32.     # usually ’/var/lib/mysql/mysql.sock’ on Linux  
  33.     # usually ’/tmp/mysql.sock’ on FreeBSD  
  34.     #  
  35.     sql_sock        = /tmp/mysql.sock  
  36.   
  37.   
  38.     # MySQL specific client connection flags  
  39.     # optional, default is 0  
  40.     # 数据传输方式  
  41.     # mysql_connect_flags    = 32 # enable compression  
  42.   
  43.     # MySQL specific SSL certificate settings  
  44.     # optional, defaults are empty  
  45.     # SLL链接  
  46.     # mysql_ssl_cert        = /etc/ssl/client-cert.pem  
  47.     # mysql_ssl_key        = /etc/ssl/client-key.pem  
  48.     # mysql_ssl_ca        = /etc/ssl/cacert.pem  
  49.   
  50.     # MS SQL specific Windows authentication mode flag  
  51.     # MUST be in sync with charset_type index-level setting  
  52.     # optional, default is 0  
  53.     #  
  54.     # mssql_winauth        = 1 # use currently logged on user credentials  
  55.   
  56.   
  57.     # MS SQL specific Unicode indexing flag  
  58.     # optional, default is 0 (request SBCS data)  
  59.     #  
  60.     # mssql_unicode        = 1 # request Unicode data from server  
  61.   
  62.   
  63.     # ODBC specific DSN (data source name)  
  64.     # mandatory for odbc source type, no default value  
  65.     #  
  66.     # odbc_dsn        = DBQ=C:\data;DefaultDir=C:\data;Driver={Microsoft Text Driver (*.txt; *.csv)};  
  67.     # sql_query        = SELECT id, data FROM documents.csv  
  68.   
  69.   
  70.     # ODBC and MS SQL specific, per-column buffer sizes  
  71.     # optional, default is auto-detect  
  72.     #  
  73.     # sql_column_buffers    = content=12M, comments=1M  
  74.   
  75.   
  76.     # pre-query, executed before the main fetch query  
  77.     # multi-value, optional, default is empty list of queries  
  78.     # 发送SQL语句前发送  
  79.     sql_query_pre        = SET NAMES utf8  
  80.     sql_query_pre        = SET SESSION query_cache_type=OFF  
  81.   
  82.   
  83.     # main document fetch query  
  84.     # mandatory, integer document ID field MUST be the first selected column  
  85.     # 需要查询的表 构建查询  
  86.     sql_query        = \  
  87.         SELECT id,target_type,genre,stars,sub_title,sports_team,music_band,music_album \  
  88.         FROM ko_link  
  89. #如果多个数据源并要在一个索引,必须要保持字段的顺序数量跟数据都要一致,否则将出错  
  90.   
  91.   
  92.     # joined/payload field fetch query  
  93.     # joined fields let you avoid (slow) JOIN and GROUP_CONCAT  
  94.     # payload fields let you attach custom per-keyword values (eg. for ranking)  
  95.     #  
  96.     # syntax is FIELD-NAME ’from’  ( ’query’ | ’payload-query’ ); QUERY  
  97.     # joined field QUERY should return 2 columns (docid, text)  
  98.     # payload field QUERY should return 3 columns (docid, keyword, weight)  
  99.     #  
  100.     # REQUIRES that query results are in ascending docuent ID order!  
  101.     # multi-value, optional, default is empty list of queries  
  102.     #  添加字段,来源与表 自动连接  
  103. # 字段结果集保持为  
  104. # (1,tags1)  
  105. # (1,tags2)  
  106. # (2,tags3)  
  107. # (2,tags4)  
  108. # 添加字段将用于搜索,结果如有第3个字段,第3个字段表示该记录的权重,权重为大于1的值  
  109.     # sql_joined_field    = tags from query; SELECT docid, CONCAT(‘tag’,tagid) FROM tags ORDER BY docid ASC  
  110.     # sql_joined_field    = wtags from payload-query; SELECT docid, tag, tagweight FROM tags ORDER BY docid ASC  
  111.   
  112.   
  113.     # file based field declaration  
  114.     #  
  115.     # content of this field is treated as a file name  
  116.     # and the file gets loaded and indexed in place of a field  
  117.     #  
  118.     # max file size is limited by max_file_field_buffer indexer setting  
  119.     # file IO errors are non-fatal and get reported as warnings  
  120.     # 把字段声明放入文件  
  121.     # sql_file_field        = content_file_path  
  122.   
  123.   
  124.     # range query setup, query that must return min and max ID values  
  125.     # optional, default is empty  
  126.     #   
  127.     # sql_query will need to reference $start and $end boundaries  
  128.     # if using ranged query:  
  129.     # 分区查询,防止MYSQL死锁  
  130.     # sql_query        = \  
  131.     #    SELECT doc.id, doc.id AS group, doc.title, doc.data \  
  132.     #    FROM documents doc \  
  133.     #    WHERE id>=$start AND id<=$end  
  134.     #  
  135.     # sql_query_range        = SELECT MIN(id),MAX(id) FROM documents  
  136.   
  137.   
  138.     # range query step  
  139.     # optional, default is 1024  
  140.     # 分区查询跳步  
  141.     # sql_range_step        = 1000  
  142.   
  143.       
  144.       
  145.       
  146.     # unsigned integer attribute declaration  
  147.     # multi-value (an arbitrary number of attributes is allowed), optional  
  148.     # optional bit size can be specified, default is 32  
  149.     # 声明无符号数字段  
  150.     #sql_attr_uint        = target_type  
  151.     # sql_attr_uint        = forum_id:9 # 9 bits for forum_id  
  152.     #sql_attr_uint        = group_id  
  153.     #声明BOOL字段  
  154.     # boolean attribute declaration  
  155.     # multi-value (an arbitrary number of attributes is allowed), optional  
  156.     # equivalent to sql_attr_uint with 1-bit size  
  157.     #  
  158.     # sql_attr_bool        = is_deleted  
  159.   
  160.   
  161.     # bigint attribute declaration  
  162.     # multi-value (an arbitrary number of attributes is allowed), optional  
  163.     # declares a signed (unlike uint!) 64-bit attribute  
  164.     # 声明长整字段  
  165.     # sql_attr_bigint        = my_bigint_id  
  166.   
  167.   
  168.     # UNIX timestamp attribute declaration  
  169.     # multi-value (an arbitrary number of attributes is allowed), optional  
  170.     # similar to integer, but can also be used in date functions  
  171.     # 声明时间字段  
  172.     # sql_attr_timestamp    = posted_ts  
  173.     # sql_attr_timestamp    = last_edited_ts  
  174.     #sql_attr_timestamp    = date_added  
  175.       
  176.     # string ordinal attribute declaration  
  177.     # multi-value (an arbitrary number of attributes is allowed), optional  
  178.     # sorts strings (bytewise), and stores their indexes in the sorted list  
  179.     # sorting by this attr is equivalent to sorting by the original strings  
  180.     # 声明字符串字段 用于排序等,但此字段不会被存储  
  181.     # sql_attr_str2ordinal    = author_name  
  182.   
  183.   
  184.     # floating point attribute declaration  
  185.     # multi-value (an arbitrary number of attributes is allowed), optional  
  186.     # values are stored in single precision, 32-bit IEEE 754 format  
  187.     # 声明浮点字段  
  188.     # sql_attr_float        = lat_radians  
  189.     # sql_attr_float        = long_radians  
  190.   
  191.   
  192.     # multi-valued attribute (MVA) attribute declaration  
  193.     # multi-value (an arbitrary number of attributes is allowed), optional  
  194.     # MVA values are variable length lists of unsigned 32-bit integers  
  195.     #  
  196.     # syntax is ATTR-TYPE ATTR-NAME ’from’ SOURCE-TYPE [;QUERY] [;RANGE-QUERY]  
  197.     # ATTR-TYPE is ’uint’ or ’timestamp’  
  198.     # SOURCE-TYPE is ’field’, ’query’, or ’ranged-query’  
  199.     # QUERY is SQL query used to fetch all ( docid, attrvalue ) pairs  
  200.     # RANGE-QUERY is SQL query used to fetch min and max ID values, similar to ’sql_query_range’  
  201.     # 声明复合字段  
  202.     # sql_attr_multi        = uint tag from query; SELECT docid, tagid FROM tags  
  203.     # sql_attr_multi        = uint tag from ranged-query; \  
  204.     #    SELECT docid, tagid FROM tags WHERE id>=$start AND id<=$end; \  
  205.     #    SELECT MIN(docid), MAX(docid) FROM tags  
  206.   
  207.   
  208.     # string attribute declaration  
  209.     # multi-value (an arbitrary number of these is allowed), optional  
  210.     # lets you store and retrieve strings  
  211.     # 只是把数据存储,但不会索引改字段  
  212.     # sql_attr_string        = stitle  
  213.   
  214.   
  215.     # wordcount attribute declaration  
  216.     # multi-value (an arbitrary number of these is allowed), optional  
  217.     # lets you count the words at indexing time  
  218.     # 将转化成关键字的字段,用于提高匹配率  
  219.     # sql_attr_str2wordcount    = stitle  
  220.   
  221.   
  222.     # combined field plus attribute declaration (from a single column)  
  223.     # stores column as an attribute, but also indexes it as a full-text field  
  224.     # 跟sql_attr_string不同是该属性加入索引  
  225.     # sql_field_string    = author  
  226.     # sql_field_str2wordcount    = title  
  227.   
  228.       
  229.     # post-query, executed on sql_query completion  
  230.     # optional, default is empty  
  231.     # 取后查询  
  232.     # sql_query_post        =  
  233.   
  234.       
  235.     # post-index-query, executed on successful indexing completion  
  236.     # optional, default is empty  
  237.     # $maxid expands to max document ID actually fetched from DB  
  238.     # 索引后查询  
  239.     # sql_query_post_index    = REPLACE INTO counters ( id, val ) \  
  240.     #    VALUES ( ’max_indexed_id’, $maxid )  
  241.   
  242.   
  243.     # ranged query throttling, in milliseconds  
  244.     # optional, default is 0 which means no delay  
  245.     # enforces given delay before each query step  
  246.     #分区查询的时间间隔  
  247.     sql_ranged_throttle    = 0  
  248.   
  249.     # document info query, ONLY for CLI search (ie. testing and debugging)  
  250.     # optional, default is empty  
  251.     # must contain $id macro and must fetch the document by that id  
  252.     #命令行调试查询结果用  
  253.     sql_query_info        = SELECT * FROM ko_link WHERE id=$id  
  254.   
  255.     # kill-list query, fetches the document IDs for kill-list  
  256.     # k-list will suppress matches from preceding indexes in the same query  
  257.     # optional, default is empty  
  258.     ##清理指定查询ID列表,对于数据的更改  
  259.     # sql_query_killlist    = SELECT id FROM documents WHERE edited>=@last_reindex  
  260.   
  261.   
  262.     # columns to unpack on indexer side when indexing  
  263.     # multi-value, optional, default is empty list  
  264.     # 启用ZIP压缩 可以降低系统负载 但必须保证zlib库zlib-dev库可用  
  265.     # unpack_zlib        = zlib_column  
  266.     # unpack_mysqlcompress    = compressed_column  
  267.     # unpack_mysqlcompress    = compressed_column_2  
  268.   
  269.   
  270.     # maximum unpacked length allowed in MySQL COMPRESS() unpacker  
  271.     # optional, default is 16M  
  272.     # 压缩缓存区大小 不能小于字段存储值  
  273.     # unpack_mysqlcompress_maxsize    = 16M  
  274.   
  275.   
  276.     #####################################################################  
  277.     ## xmlpipe2 配置  
  278.     #####################################################################  
  279.   
  280.     # type            = xmlpipe  
  281.   
  282.     # shell command to invoke xmlpipe stream producer  
  283.     # mandatory  
  284.     #  
  285.     # xmlpipe_command        = cat /usr/local/sphinx/var/test.xml  
  286.   
  287.     # xmlpipe2 field declaration  
  288.     # multi-value, optional, default is empty  
  289.     #  
  290.     # xmlpipe_field        = subject  
  291.     # xmlpipe_field        = content  
  292.   
  293.   
  294.     # xmlpipe2 attribute declaration  
  295.     # multi-value, optional, default is empty  
  296.     # all xmlpipe_attr_XXX options are fully similar to sql_attr_XXX  
  297.     #  
  298.     # xmlpipe_attr_timestamp    = published  
  299.     # xmlpipe_attr_uint    = author_id  
  300.   
  301.   
  302.     # perform UTF-8 validation, and filter out incorrect codes  
  303.     # avoids XML parser choking on non-UTF-8 documents  
  304.     # optional, default is 0  
  305.     #  
  306.     # xmlpipe_fixup_utf8    = 1  
  307. }  
  308.   
  309.   
  310. # inherited source example  
  311. # 继承数据源  
  312. # all the parameters are copied from the parent source,  
  313. # and may then be overridden in this source definition  
  314. #source src1throttled : src1  
  315. #{  
  316. #    sql_ranged_throttle    = 100  
  317. #}  
  318.   
  319. #############################################################################  
  320. ## index definition  
  321. #############################################################################  
  322.   
  323. # local index example  
  324. #  
  325. # this is an index which is stored locally in the filesystem  
  326. #  
  327. # all indexing-time options (such as morphology and charsets)  
  328. # are configured per local index  
  329. index test1  
  330. {  
  331.     # index type  
  332.     # optional, default is ’plain’  
  333.     # known values are ’plain’, ’distributed’, and ’rt’ (see samples below)   
  334.     #索引类型 本地 分布式   
  335.     # type            = plain  
  336.   
  337.     # document source(s) to index  
  338.     # multi-value, mandatory  
  339.     # document IDs must be globally unique across all sources  
  340.     #数据源,可以多个数据源  
  341.     source            = src1  
  342.   
  343.     # index files path and file name, without extension  
  344.     # mandatory, path must be writable, extensions will be auto-appended  
  345.     # 索引保存路径  
  346.     path            = /usr/local/sphinx/var/data/test1  
  347.   
  348.     # document attribute values (docinfo) storage mode  
  349.     # optional, default is ’extern’  
  350.     # known values are ’none’, ’extern’ and ’inline’  
  351.     #索引存储方式  
  352.     docinfo            = extern  
  353.   
  354.     # memory locking for cached data (.spa and .spi), to prevent swapping  
  355.     # optional, default is 0 (do not mlock)  
  356.     # requires searchd to be run from root  
  357.     #内存锁定 需要保证足够权限  
  358.     mlock            = 0  
  359.   
  360.     # a list of morphology preprocessors to apply  
  361.     # optional, default is empty  
  362.     #  
  363.     # builtin preprocessors are ’none’, ’stem_en’, ’stem_ru’, ’stem_enru’,  
  364.     # ’soundex’, and ’metaphone’; additional preprocessors available from  
  365.     # libstemmer are ’libstemmer_XXX’, where XXX is algorithm code  
  366.     # (see libstemmer_c/libstemmer/modules.txt)  
  367.     # 词语提取器  
  368.     # morphology        = stem_en, stem_ru, soundex  
  369.     # morphology        = libstemmer_german  
  370.     # morphology        = libstemmer_sv  
  371.     morphology        = stem_en  
  372.   
  373.     # minimum word length at which to enable stemming  
  374.     # optional, default is 1 (stem everything)  
  375.     # 词干化的最小词长  
  376.     # min_stemming_len    = 1  
  377.   
  378.   
  379.     # stopword files list (space separated)  
  380.     # optional, default is empty  
  381.     # contents are plain text, charset_table and stemming are both applied  
  382.     # 停用搜索词  
  383.     # stopwords        = /usr/local/sphinx/var/data/stopwords.txt  
  384.   
  385.   
  386.     # wordforms file, in ”mapfrom > mapto” plain text format  
  387.     # optional, default is empty  
  388.     # 词型字典 可用spelldump工具生成  
  389.     # wordforms        = /usr/local/sphinx/var/data/wordforms.txt  
  390.   
  391.   
  392.     # tokenizing exceptions file  
  393.     # optional, default is empty  
  394.     #Token特例文件,就是有些词是完整词意,不能拆分索引如a&t 跟a & t  
  395.     # plain text, case sensitive, space insensitive in map-from part  
  396.     # one ”Map Several Words => ToASingleOne” entry per line  
  397.     #  
  398.     # exceptions        = /usr/local/sphinx/var/data/exceptions.txt  
  399.   
  400.   
  401.     # minimum indexed word length  
  402.     # default is 1 (index everything)  
  403.     #  最小索引长度,就是小于指定长度的词不被索引  
  404.     min_word_len        = 1  
  405.   
  406.     # charset encoding type  
  407.     # optional, default is ’sbcs’  
  408.     # known types are ’sbcs’ (Single Byte CharSet) and ’utf-8′  
  409.     # 字符编码  
  410.     charset_type        = utf-8  
  411.   
  412.     # charset definition and case folding rules ”table”  
  413.     # optional, default value depends on charset_type  
  414.     #  
  415.     # defaults are configured to include English and Russian characters only  
  416.     # you need to change the table to include additional ones  
  417.     # this behavior MAY change in future versions  
  418.     #  
  419.     # ’sbcs’ default value is  
  420.     # charset_table        = 0..9, A..Z->a..z, _, a..z, U+A8->U+B8, U+B8, U+C0..U+DF->U+E0..U+FF, U+E0..U+FF  
  421.     # 转换字符表  
  422.     # ’utf-8′ default value is  
  423.     # charset_table        = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F  
  424.   
  425.   
  426.     # ignored characters list  
  427.     # optional, default value is empty  
  428.     #  忽略字符表  
  429.     # ignore_chars        = U+00AD  
  430.   
  431.   
  432.     # minimum word prefix length to index  
  433.     # optional, default is 0 (do not index prefixes)  
  434.     #索引的最小前缀长度,小心使用,索引和搜索的时间皆会恶化  
  435.     # min_prefix_len        = 0  
  436.   
  437.   
  438.     # minimum word infix length to index  
  439.     # optional, default is 0 (do not index infixes)  
  440.     #索引的最小中缀长度 小心使用,索引和搜索的时间皆会恶化  
  441.     # min_infix_len        = 0  
  442.   
  443.   
  444.     # list of fields to limit prefix/infix indexing to  
  445.     # optional, default value is empty (index all fields in prefix/infix mode)  
  446.     # 未知  
  447.     # prefix_fields        = filename  
  448.     # infix_fields        = url, domain  
  449.   
  450.   
  451.     # enable star-syntax (wildcards) when searching prefix/infix indexes  
  452.     # search-time only, does not affect indexing, can be 0 or 1  
  453.     # optional, default is 0 (do not use wildcard syntax)  
  454.     # 启用星号语法  
  455.     # enable_star        = 1  
  456.   
  457.   
  458.     # expand keywords with exact forms and/or stars when searching fit indexes  
  459.     # search-time only, does not affect indexing, can be 0 or 1  
  460.     # optional, default is 0 (do not expand keywords)  
  461.     # 扩大搜索关键字 形式如: running -> ( running | *running* | =running )  
  462.     # expand_keywords        = 1  
  463.   
  464.       
  465.     # n-gram length to index, for CJK indexing  
  466.     # only supports 0 and 1 for now, other lengths to be implemented  
  467.     # optional, default is 0 (disable n-grams)  
  468.     # 中文等其他语言的基本支持  
  469.     # ngram_len        = 1  
  470.   
  471.   
  472.     # n-gram characters list, for CJK indexing  
  473.     # optional, default is empty  
  474.     #中文或其他语言的值范围  
  475.     # ngram_chars        = U+3000..U+2FA1F  
  476.   
  477.   
  478.     # phrase boundary characters list  
  479.     # optional, default is empty  
  480.     # 边界符  
  481.     # phrase_boundary        = ., ?, !, U+2026 # horizontal ellipsis  
  482.   
  483.   
  484.     # phrase boundary word position increment  
  485.     # optional, default is 0  
  486.     # 边界符增量  
  487.     # phrase_boundary_step    = 100  
  488.   
  489.   
  490.     # blended characters list  
  491.     # blended chars are indexed both as separators and valid characters  
  492.     # for instance, AT&T will results in 3 tokens (“at”, ”t”, and ”at&t”)  
  493.     # optional, default is empty  
  494.     # 混合字符列表  
  495.     # blend_chars        = +, &, U+23  
  496.   
  497.   
  498.     # blended token indexing mode  
  499.     # a comma separated list of blended token indexing variants  
  500.     # known variants are trim_none, trim_head, trim_tail, trim_both, skip_pure  
  501.     # optional, default is trim_none  
  502.     #未知  
  503.     # blend_mode        = trim_tail, skip_pure  
  504.   
  505.   
  506.     # whether to strip HTML tags from incoming documents  
  507.     # known values are 0 (do not strip) and 1 (do strip)  
  508.     # optional, default is 0  
  509.     # 删除HTML标签 (小心文本被删除)  
  510.     html_strip        = 0  
  511.   
  512.     # what HTML attributes to index if stripping HTML  
  513.     # optional, default is empty (do not index anything)  
  514.     # 保留的HTML标签  
  515.     # html_index_attrs    = img=alt,title; a=title;  
  516.   
  517.   
  518.     # what HTML elements contents to strip  
  519.     # optional, default is empty (do not strip element contents)  
  520.     # 不但删除标签,其包含的文本也将删除  
  521.     # html_remove_elements    = style, script  
  522.   
  523.   
  524.     # whether to preopen index data files on startup  
  525.     # optional, default is 0 (do not preopen), searchd-only  
  526.     # 预先打开索引还是每次查询的时候在打开索引  
  527.     # preopen            = 1  
  528.   
  529.   
  530.     # whether to keep dictionary (.spi) on disk, or cache it in RAM  
  531.     # optional, default is 0 (cache in RAM), searchd-only  
  532.     # 将字典文件是否保存在内存中  
  533.     # ondisk_dict        = 1  
  534.   
  535.   
  536.     # whether to enable in-place inversion (2x less disk, 90-95% speed)  
  537.     # optional, default is 0 (use separate temporary files), indexer-only  
  538.     # 是否启用原地索引倒转 将少磁盘使用 性能会有一点损失  
  539.     # inplace_enable        = 1  
  540.   
  541.   
  542.     # in-place fine-tuning options  
  543.     # optional, defaults are listed below  
  544.     #微调原地倒转  
  545.     # inplace_hit_gap        = 0 # preallocated hitlist gap size   
  546.     # inplace_docinfo_gap    = 0 # preallocated docinfo gap size  
  547.     # inplace_reloc_factor    = 0.1 # relocation buffer size within arena  
  548.     # inplace_write_factor    = 0.1 # write buffer size within arena  
  549.   
  550.   
  551.     # whether to index original keywords along with stemmed versions  
  552.     # enables ”=exactform” operator to work  
  553.     # optional, default is 0  
  554.     # 是否在索引原关键词的词干化/重映射后的形式的同时也索引原词  
  555.     # index_exact_words    = 1  
  556.   
  557.   
  558.     # position increment on overshort (less that min_word_len) words  
  559.     # optional, allowed values are 0 and 1, default is 1  
  560.     #在经过过短的词(比 min_word_len短的词)处后增加位置值  
  561.     # overshort_step        = 1  
  562.   
  563.   
  564.     # position increment on stopword  
  565.     # optional, allowed values are 0 and 1, default is 1  
  566.     #在经过 停用词 处后增加位置值可选选项  
  567.     # stopword_step        = 1  
  568.   
  569.   
  570.     # hitless words list  
  571.     # positions for these keywords will not be stored in the index  
  572.     # optional, allowed values are ’all’, or a list file name  
  573.     # 不能中断的字符列表  
  574.     # hitless_words        = all  
  575.     # hitless_words        = hitless.txt #字符文件  
  576.   
  577.   
  578.     # detect and index sentence and paragraph boundaries  
  579.     # required for the SENTENCE and PARAGRAPH operators to work  
  580.     # optional, allowed values are 0 and 1, default is 0  
  581.     # 是否检查标签合并 针对HTML  
  582.     # index_sp            = 1  
  583.   
  584.   
  585.     # index zones, delimited by HTML/XML tags  
  586.     # a comma separated list of tags and wildcards  
  587.     # required for the ZONE operator to work  
  588.     # optional, default is empty string (do not index zones)  
  589.     # 对HTML标签的权重  
  590.     # index_zones        = title, h*, th  
  591. }  
  592.   
  593.   
  594. # inherited index example  
  595. # 索引继承  
  596. # all the parameters are copied from the parent index,  
  597. # and may then be overridden in this index definition  
  598. #index test1stemmed : test1  
  599. #{  
  600. #    path            = /usr/local/sphinx/var/data/test1stemmed  
  601. #    morphology        = stem_en  
  602. #}  
  603.   
  604.   
  605. # distributed index example  
  606. #  
  607. # this is a virtual index which can NOT be directly indexed,  
  608. # and only contains references to other local and/or remote indexes  
  609. #index dist1  
  610. #{  
  611. #分布式索引配置  
  612.     # ’distributed’ index type MUST be specified  
  613. #    type            = distributed  
  614.   
  615.     # local index to be searched  
  616.     # there can be many local indexes configured  
  617. #    local            = test1  
  618. #    local            = test1stemmed  
  619.   
  620.     # remote agent  
  621.     # multiple remote agents may be specified  
  622.     # syntax for TCP connections is ’hostname:port:index1,[index2[,...]]’  
  623.     # syntax for local UNIX connections is ’/path/to/socket:index1,[index2[,...]]’  
  624. #    agent            = localhost:9313:remote1  
  625. #    agent            = localhost:9314:remote2,remote3  
  626.     # agent            = /var/run/searchd.sock:remote4  
  627.   
  628.     # blackhole remote agent, for debugging/testing  
  629.     # network errors and search results will be ignored  
  630.     #  
  631.     # agent_blackhole        = testbox:9312:testindex1,testindex2  
  632.   
  633.   
  634.     # remote agent connection timeout, milliseconds  
  635.     # optional, default is 1000 ms, ie. 1 sec  
  636. #    agent_connect_timeout    = 1000  
  637.   
  638.     # remote agent query timeout, milliseconds  
  639.     # optional, default is 3000 ms, ie. 3 sec  
  640. #    agent_query_timeout    = 3000  
  641. #}  
  642.   
  643.   
  644. # realtime index example  
  645. #  
  646. # you can run INSERT, REPLACE, and DELETE on this index on the fly  
  647. # using MySQL protocol (see ’listen’ directive below)  
  648. #index rt  
  649. #{  
  650.     # ’rt’ index type must be specified to use RT index  
  651. #    type            = rt  
  652.   
  653.     # index files path and file name, without extension  
  654.     # mandatory, path must be writable, extensions will be auto-appended  
  655.   
  656. #    path            = /usr/local/sphinx/var/data/rt  
  657.   
  658.     # RAM chunk size limit  
  659.     # RT index will keep at most this much data in RAM, then flush to disk  
  660.     # optional, default is 32M  
  661.     #  
  662.     # rt_mem_limit        = 512M  
  663.   
  664.     # full-text field declaration  
  665.     # multi-value, mandatory  
  666. #    rt_field        = title  
  667. #    rt_field        = content  
  668.   
  669.     # unsigned integer attribute declaration  
  670.     # multi-value (an arbitrary number of attributes is allowed), optional  
  671.     # declares an unsigned 32-bit attribute  
  672. #    rt_attr_uint        = gid  
  673.   
  674.     # RT indexes currently support the following attribute types:  
  675.     # uint, bigint, float, timestamp, string  
  676.     #  
  677.     # rt_attr_bigint        = guid  
  678.     # rt_attr_float        = gpa  
  679.     # rt_attr_timestamp    = ts_added  
  680.     # rt_attr_string        = author  
  681. #}  
  682.   
  683. #############################################################################  
  684. ## indexer settings  
  685. #############################################################################  
  686.   
  687. indexer  
  688. {  
  689.     #索引过程内存使用限制。可选选项,默认32M。   
  690.     # memory limit, in bytes, kiloytes (16384K) or megabytes (256M)  
  691.     # optional, default is 32M, max is 2047M, recommended is 256M to 1024M  
  692.     mem_limit        = 32M  
  693.   
  694.     # maximum IO calls per second (for I/O throttling)  
  695.     # optional, default is 0 (unlimited)  
  696.     # 每秒最大I/O操作次数,用于限制I/O操作。可选选项,默认为0(无限制)。   
  697.     # max_iops        = 40  
  698.   
  699.   
  700.     # maximum IO call size, bytes (for I/O throttling)  
  701.     # optional, default is 0 (unlimited)  
  702.     # 最大允许的I/O操作大小,以字节为单位,用于I/O节流。可选选项,默认为0(不限制)。   
  703.     # max_iosize        = 1048576  
  704.   
  705.   
  706.     # maximum xmlpipe2 field length, bytes  
  707.     # optional, default is 2M  
  708.     # 对于XMLLpipe2数据源允许的最大的域大小  
  709.     # max_xmlpipe2_field    = 4M  
  710.   
  711.   
  712.     # write buffer size, bytes  
  713.     # several (currently up to 4) buffers will be allocated  
  714.     # write buffers are allocated in addition to mem_limit  
  715.     # optional, default is 1M  
  716.     # 写缓冲区的大小,单位是字节。可选选项,默认值是1MB。   
  717.     # write_buffer        = 1M  
  718.   
  719.   
  720.     # maximum file field adaptive buffer size  
  721.     # optional, default is 8M, minimum is 1M  
  722.     #  
  723.     # max_file_field_buffer    = 32M  
  724. }  
  725.   
  726. #############################################################################  
  727. ## searchd settings  
  728. #############################################################################  
  729.   
  730. searchd  
  731. {  
  732.     # [hostname:]port[:protocol], or /unix/socket/path to listen on  
  733.     # known protocols are ’sphinx’ (SphinxAPI) and ’mysql41′ (SphinxQL)  
  734.     #  
  735.     # multi-value, multiple listen points are allowed  
  736.     # optional, defaults are 9312:sphinx and 9306:mysql41, as below  
  737.     #  
  738.     # listen            = 127.0.0.1  
  739.     # listen            = 192.168.0.1:9312  
  740.     # listen            = 9312  
  741.     # listen            = /var/run/searchd.sock  
  742.     listen            = 9312  
  743.     #listen            = 9306:mysql41  
  744.   
  745.     # log file, searchd run info is logged here  
  746.     # optional, default is ’searchd.log’  
  747.     # 全部searchd运行时事件会被记录在这个日志文件中。   
  748.     log            = /usr/local/sphinx/var/log/searchd.log  
  749.   
  750.     # query log file, all search queries are logged here  
  751.     # optional, default is empty (do not log queries)  
  752.     # 全部搜索查询会被记录在此文件中。  
  753.     query_log        = /usr/local/sphinx/var/log/query.log  
  754.   
  755.     # client read timeout, seconds  
  756.     # optional, default is 5  
  757.     #网络客户端请求的读超时时间,单位是秒。  
  758.     read_timeout        = 5  
  759.   
  760.     # request timeout, seconds  
  761.     # optional, default is 5 minutes  
  762.     #在使用持久连接时,两次查询之间等待的最长时间(单位是秒)。  
  763.     client_timeout        = 300  
  764.   
  765.     # maximum amount of children to fork (concurrent searches to run)  
  766.     # optional, default is 0 (unlimited)  
  767.     #子进程的最大数量 ,用来控制服务器负载。任何时候不可能有比此设置值更多的搜索同时运行。当达到限制时,新的输入客户端会被用临时失败(SEARCH_RETRY)状态码驳回,同时给出一个声明服务器已到最大连接限制的消息。   
  768.     max_children        = 30  
  769.   
  770.     # PID file, searchd process ID file name  
  771.     # mandatory  
  772.     #进程ID文件  
  773.     pid_file        = /usr/local/sphinx/var/log/searchd.pid  
  774.   
  775.     # max amount of matches the daemon ever keeps in RAM, per-index  
  776.     # WARNING, THERE’S ALSO PER-QUERY LIMIT, SEE SetLimits() API CALL  
  777.     # default is 1000 (just like Google)  
  778.     #守护进程在内存中为每个索引所保持并返回给客户端的匹配数目的最大值。  
  779.     max_matches        = 1000  
  780.   
  781.     # seamless rotate, prevents rotate stalls if precaching huge datasets  
  782.     # optional, default is 1  
  783.     #防止 searchd 轮换在需要预取大量数据的索引时停止响应。可选选项,默认为1(启用无缝(seamless)轮换)。   
  784.     seamless_rotate        = 1  
  785.   
  786.     # whether to forcibly preopen all indexes on startup  
  787.     # optional, default is 1 (preopen everything)  
  788.     #是否在启动是强制重新打开所有索引文件。可选选项,默认为0(不重新打开)。  
  789.     preopen_indexes        = 1  
  790.   
  791.     # whether to unlink .old index copies on succesful rotation.  
  792.     # optional, default is 1 (do unlink)  
  793.     #索引轮换成功之后,是否删除以.old为扩展名的索引拷贝。可选选项,默认为1(删除这些索引拷贝)。   
  794.     unlink_old        = 1  
  795.   
  796.     # attribute updates periodic flush timeout, seconds  
  797.     # updates will be automatically dumped to disk this frequently  
  798.     # optional, default is 0 (disable periodic flush)  
  799.     # UpdateAttributes() 调用时候更新是否隔一段时间写入磁盘  
  800.     # attr_flush_period    = 900  
  801.   
  802.   
  803.     # instance-wide ondisk_dict defaults (per-index value take precedence)  
  804.     # optional, default is 0 (precache all dictionaries in RAM)  
  805.     #对 ondisk_dict 指令的全局的默认值。 可选选项,默认值是0(将字典预先缓冲到内存)。  
  806.     # ondisk_dict_default    = 1  
  807.   
  808.   
  809.     # MVA updates pool size  
  810.     # shared between all instances of searchd, disables attr flushes!  
  811.     # optional, default size is 1M  
  812.     #网络通讯时允许的最大的包的大小。  
  813.     mva_updates_pool    = 1M  
  814.   
  815.     # max allowed network packet size  
  816.     # limits both query packets from clients, and responses from agents  
  817.     # optional, default size is 8M  
  818.     #用于多值属性MVA更新的存储空间的共享池大小。  
  819.     max_packet_size        = 8M  
  820.   
  821.     # crash log path  
  822.     # searchd will (try to) log crashed query to ’crash_log_path.PID’ file  
  823.     # optional, default is empty (do not create crash logs)  
  824.     #崩溃日志文件的路径  
  825.     # crash_log_path        = /usr/local/sphinx/var/log/crash  
  826.   
  827.   
  828.     # max allowed per-query filter count  
  829.     # optional, default is 256  
  830.     #每次查询允许设置的过滤器的最大个数。只用于内部检查,不直接影响内存使用或性能。  
  831.     max_filters        = 256  
  832.   
  833.     # max allowed per-filter values count  
  834.     # optional, default is 4096  
  835.     #单个过滤器允许的值的最大个数。只用于内部检查,不直接影响内存使用或性能。  
  836.     max_filter_values    = 4096  
  837.   
  838.   
  839.     # socket listen queue length  
  840.     # optional, default is 5  
  841.     #TCP监听积压列表长度。无法如对的请求立即失败并收到“连接被拒”错误信息  
  842.     # listen_backlog        = 5  
  843.   
  844.   
  845.     # per-keyword read buffer size  
  846.     # optional, default is 256K  
  847.     #每个关键字的读缓冲区的大小。可选选项,默认值是256K。   
  848.     # read_buffer        = 256K  
  849.   
  850.   
  851.     # unhinted read size (currently used when reading hits)  
  852.     # optional, default is 32K  
  853.     #无提示时读操作的大小。可选选项,默认值是32K。  
  854.     # read_unhinted        = 32K  
  855.   
  856.   
  857.     # max allowed per-batch query count (aka multi-query count)  
  858.     # optional, default is 32  
  859.     #限制每批次的查询量。一个OPEN之后的查询量  
  860.     max_batch_queries    = 32  
  861.   
  862.   
  863.     # max common subtree document cache size, per-query  
  864.     # optional, default is 0 (disable subtree optimization)  
  865.     #  
  866.     # subtree_docs_cache    = 4M  
  867.   
  868.   
  869.     # max common subtree hit cache size, per-query  
  870.     # optional, default is 0 (disable subtree optimization)  
  871.     # 限制RAM使用一个共同的子树优化 默认不优化  
  872.     # subtree_hits_cache    = 8M  
  873.   
  874.   
  875.     # multi-processing mode (MPM)  
  876.     # known values are none, fork, prefork, and threads  
  877.     # optional, default is fork  
  878.     # 工作方式   
  879.     workers            = threads # for RT to work  
  880.   
  881.   
  882.     # max threads to create for searching local parts of a distributed index  
  883.     # optional, default is 0, which means disable multi-threaded searching  
  884.     # should work with all MPMs (ie. does NOT require workers=threads)  
  885.     #    
  886.     # dist_threads        = 4  
  887.   
  888.   
  889.     # binlog files path; use empty string to disable binlog  
  890.     # optional, default is build-time configured data directory  
  891.     # 二进制日志路径  
  892.     # binlog_path        = # disable logging  
  893.     # binlog_path        = /usr/local/sphinx/var/data # binlog.001 etc will be created there  
  894.   
  895.   
  896.     # binlog flush/sync mode  
  897.     # 0 means flush and sync every second  
  898.     # 1 means flush and sync every transaction  
  899.     # 2 means flush every transaction, sync every second  
  900.     # optional, default is 2  
  901.     # 日志刷新模式  
  902.     # binlog_flush        = 2  
  903.   
  904.   
  905.     # binlog per-file size limit  
  906.     # optional, default is 128M, 0 means no limit  
  907.     #最大日志大小  
  908.     # binlog_max_log_size    = 256M  
  909.   
  910.   
  911.     # per-thread stack size, only affects workers=threads mode  
  912.     # optional, default is 64K  
  913.     #每个线程的堆栈大小。  
  914.     # thread_stack            = 128K  
  915.   
  916.   
  917.     # per-keyword expansion limit (for dict=keywords prefix searches)  
  918.     # optional, default is 0 (no limit)  
  919.     # 扩大为一个关键字的最大数目  
  920.     # expansion_limit        = 1000  
  921.   
  922.   
  923.     # RT RAM chunks flush period  
  924.     # optional, default is 0 (no periodic flush)  
  925.     #RT索引在内存中检查的时间  
  926.     # rt_flush_period        = 900  
  927.   
  928.   
  929.     # query log file format  
  930.     # optional, known values are plain and sphinxql, default is plain  
  931.     # 查询日志格式  
  932.     # query_log_format        = sphinxql  
  933.   
  934.   
  935.     # version string returned to MySQL network protocol clients  
  936.     # optional, default is empty (use Sphinx version)  
  937.     # MYSQL版本  
  938.     # mysql_version_string    = 5.0.37  
  939.   
  940.   
  941.     # trusted plugin directory  
  942.     # optional, default is empty (disable UDFs)  
  943.     # 插件目录  
  944.     # plugin_dir            = /usr/local/sphinx/lib  
  945.   
  946.   
  947.     # default server-wide collation  
  948.     # optional, default is libc_ci  
  949.     # 链接字符集  
  950.     # collation_server        = utf8_general_ci  
  951.   
  952.   
  953.     # server-wide locale for libc based collations  
  954.     # optional, default is C  
  955.     # collation 选项  
  956.     # collation_libc_locale    = ru_RU.UTF-8  
  957.   
  958.   
  959.     # threaded server watchdog (only used in workers=threads mode)  
  960.     # optional, values are 0 and 1, default is 1 (watchdog on)  
  961.     # 是否启用服务器监控进程  
  962.     # watchdog                = 1  
  963.   
  964.       
  965.     # SphinxQL compatibility mode (legacy columns and their names)  
  966.     # optional, default is 0 (SQL compliant syntax and result sets)  
  967.     #sphinxql 兼容模式  
  968.     # compat_sphinxql_magics    = 1  
  969. }  
  970.   
  971. # –eof–  

 

建立索引:
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx.conf index1
不停服务下索引: 
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx.conf –all –rotate
启动索引服务,使PHP的客户端可用
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx.conf 
建立PHP测试文件

<?php      $s = new SphinxClient;      setServer(“localhost”, 9312);      $s->setMatchMode(SPH_MATCH_ANY);      $s->setMaxQueryTime(3);      $result = $s->query(“test”);#查询     print_r ($result); ?>
运行即可

searchd 命令:

强行停止:

searchd –config /home/myuser/sphinx.conf –stop

 

安静停止:

searchd –config /home/myuser/sphinx.conf –stopwait

 

状态:

 

searchd –config /home/myuser/sphinx.conf –status

 

指定PID文件

searchd –config /home/myuser/sphinx.conf –pidfile /home/myuser/sphinx.pid

 

启动的为控制台模式:

searchd –config /home/myuser/sphinx.conf –console

 

只启动指定索引

searchd –index myindex

 

生成一些字典的工具软件:spelldump

indextool 一些转移等工具的软件

搜索字符串规则:

 

* operator OR:
hello | world

* operator NOT:
hello -world
hello !world

* field search operator:
@title hello @body world

* field position limit modifier (introduced in version 0.9.9-rc1):
@body[50] hello

* multiple-field search operator:
@(title,body) hello world

* all-field search operator:
@* hello

* phrase search operator:
“hello world”

* proximity search operator:
“hello world”~10

* quorum matching operator:
“the world is a wonderful place”/3

* strict order operator (aka operator ”before”):
aaa << bbb << ccc

* exact form modifier (introduced in version 0.9.9-rc1):
raining =cats and =dogs

* field-start and field-end modifier (introduced in version 0.9.9-rc2):
^hello world$

* NEAR, generalized proximity operator (introduced in version
2.0.1-beta):
hello NEAR/3 world NEAR/4 ”my test”

* SENTENCE operator (introduced in version 2.0.1-beta):
all SENTENCE words SENTENCE ”in one sentence”

* PARAGRAPH operator (introduced in version 2.0.1-beta):
“Bill Gates” PARAGRAPH ”Steve Jobs”

* zone limit operator:
ZONE:(h3,h4) only in these titles

 

表达式,支持函数等 日期用的是时间戳 (好像不是作为MYSQL存储引擎的时候用不到)

* Arithmetic operators: +, -, *, /, %, DIV, MOD
* Comparison operators: <, > <=, >=, =, <>
* Boolean operators: AND, OR, NOT
* Bitwise operators: &, |
* ABS()
* BIGINT()
* CEIL()
* COS()
* CRC32()
* DAY()
* EXP()
* FLOOR()
* GEODIST()
* IDIV()
* IF()
* IN()
* INTERVAL()
* LN()
* LOG10()
* LOG2()
* MAX()
* MIN()
* MONTH()
* NOW()
* POW()
* SIN()
* SINT()
* SQRT()
* YEAR()
* YEARMONTH()
* YEARMONTHDAY()

 

 

  1. <?php   
  2.   
  3. include_once ‘sphinxapi.php’;  
  4. $s = new SphinxClient();  
  5. $s->setServer(“localhost”, 9312);  
  6. $s->SetConnectTimeout ( 1 );//设置链接超时  
  7.   
  8.   
  9. /* 
  10. $s->AddQuery();//列表查询 
  11. $s->RunQueries ();//执行列表查询 
  12. $s->ResetFilters();//清除过滤条件 
  13. $s->BuildExcerpts($docs, $index, $words);//生成简要 
  14. $s->BuildKeywords($query, $index, $hits);//生成关键字 
  15. $s->GetLastError();//错误 
  16. $s->GetLastWarning();//警告 
  17. $s->FlushAttributes();//索引刷入硬盘 
  18. $s->IsConnectError();//链接错误 
  19. $s->ResetGroupBy();//重设分组 
  20.  
  21. $s->SetFieldWeights(array(‘sub_title’=>1));//加权最小为1 
  22. $s->SetIDRange($min, $max);//ID范围 
  23. $s->SetIndexWeights(array(‘test1′=>1));//索引权重 
  24. $s->Status();//服务是否可用 
  25. $s->UpdateAttributes($index, $attrs, $values);//更新硬盘索引 
  26. */  
  27. /* 
  28. 参考文档:http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html#matching-modes 
  29. SPH_MATCH_ALL, matches all query words (default mode); 
  30. SPH_MATCH_ANY, matches any of the query words; 
  31. SPH_MATCH_PHRASE, matches query as a phrase, requiring perfect match; 
  32. SPH_MATCH_BOOLEAN, matches query as a boolean expression (see Section 5.2, “Boolean query syntax”); 
  33. SPH_MATCH_EXTENDED, matches query as an expression in Sphinx internal query language (see Section 5.3, “Extended query syntax”). As of 0.9.9, this has been superceded by SPH_MATCH_EXTENDED2, providing additional functionality and better performance. The ident is retained for legacy application code that will continue to be compatible once Sphinx and its components, including the API, are upgraded. 
  34. SPH_MATCH_EXTENDED2, matches query using the second version of the Extended matching mode. 
  35. SPH_MATCH_FULLSCAN, m 
  36. */  
  37. $s->setMatchMode(SPH_MATCH_ANY);//匹配模式  
  38. $s->setMaxQueryTime(3);//查询超时  
  39. //$s->SetSelect ( $select );//设置返回的字段  
  40. /* 
  41. $cl->SetSelect ( ”*, @weight+(user_karma+ln(pageviews))*0.1 AS myweight” ); 
  42. $cl->SetSelect ( ”exp_years, salary_gbp*{$gbp_usd_rate} AS salary_usd, 
  43.    IF(age>40,1,0) AS over40″ ); 
  44. $cl->SetSelect ( ”*, AVG(price) AS avgprice” ); 
  45.  */  
  46.   
  47. /* 
  48. $cl->SetGroupBy ( ”category”, SPH_GROUPBY_ATTR, ”@count desc” ); 
  49. $cl->SetGroupDistinct ( ”vendor” ); 
  50. == 
  51. SELECT id, weight, all-attributes, 
  52.     COUNT(DISTINCT vendor) AS @distinct, 
  53.     COUNT(*) AS @count 
  54. FROM products 
  55. GROUP BY category 
  56. ORDER BY @count DESC 
  57. */  
  58. //$s->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );//汇总  
  59. //$s->SetGroupDistinct ( $distinct );//设置不重复字段  
  60.   
  61. $s->SetArrayResult ( true );//结果是否有ID  
  62.   
  63. /* 
  64.     SPH_SORT_RELEVANCE mode, that sorts by relevance in descending order (best matches first); 
  65.     SPH_SORT_ATTR_DESC mode, that sorts by an attribute in descending order (bigger attribute values first); 
  66.     SPH_SORT_ATTR_ASC mode, that sorts by an attribute in ascending order (smaller attribute values first); 
  67.     SPH_SORT_TIME_SEGMENTS mode, that sorts by time segments (last hour/day/week/month) in descending order, and then by relevance in descending order; 
  68.     SPH_SORT_EXTENDED mode, that sorts by SQL-like combination of columns in ASC/DESC order; 
  69.     SPH_SORT_EXPR mode, that sorts by an arithmetic expression. 
  70.  */  
  71. //$s->SetSortMode ( SPH_SORT_EXTENDED, $sortby );//排序模式  
  72.   
  73. /* 
  74. $s->SetOverride($attrname, $attrtype, $values); 
  75. $s->ResetOverrides();*/  
  76. /* 
  77. $s->SetRetries($count);//设置失败重试 
  78. $s->SetRankingMode($ranker);//设置排名模式 均适用于SPH_MATCH_EXTENDED2搜索 
  79.  
  80. //第3个参数当为true时,相当于$attribute!=$value,默认值是false 
  81. $s->SetFilter ( ’target_type’, $filtervals );//设置过滤,值列表 
  82. $s->SetFilterFloatRange($attribute, $min, $max);//浮动范围 
  83. $s->SetFilterRange($attribute, $min, $max);//指定范围 
  84. $s->SetGeoAnchor($attrlat, $attrlong, $lat, $long); 
  85. */  
  86. //link  
  87. //$s->SetFilter ( ’target_type’, array(1),true );  
  88.   
  89.   
  90. $s->SetLimits ( 0, 10 );//显示数量:开始 量 最大量 右偏移量  
  91. $result = $s->query(“good”,“team”);//查询  
  92.   
  93.   
  94. print_r($result);  

撒花庆贺~博客搬家完成

从国外把博客给搬回来了。。。BurstNet的速度果然让人hold不住。。。

还是安心用国内的服务器吧。。。贵点就贵点了。。。

ImageImagick + PHP + Apache On WINDOWS

今天帮同事安装配置php_imagick,结果装是装上了apache也能正常启动,但是程序一new Imagick()就会导致Apache崩溃。

在google之后从Stack Overflow找到问题原因:

I’ve had the same issue today. You have to install version of Image Magick no higher than 6.6.4.0 – next builds are made using VC10 which seems to be incompatible with Apache VC9 + PHP5.3.x VC9.

 

ImageImagick dll for windows 在6.6.4以后用的都是VC10编译,所以不兼容vc9编译的php,虽然apache能正常启动,但是new Imagick的时候会导致apache崩溃。

解决办法就是安装低版本的ImageImagick

下载地址:http://image_magick.veidrodis.com/image_magick/binaries/

 

参考资料:

http://stackoverflow.com/questions/8608426/imagick-crash-with-php-5-3

http://www.elxsy.com/2009/07/installing-imagemagick-on-windows-and-using-with-php-imagick/

修复zsh svn1.7 自动完成的问题

更新svn(subversion)到1.7后 zsh 的svn自动完成就傻X了。

错误: _arguments:comparguments:312: invalid argument: [--cl]:arg:

修改方法

打开文件:/usr/share/zsh/4.3.11/functions/_subversion

找到35行左右

${=${${${(M)${(f)”$(LC_ALL=C _call_program options svn help $cmd)”#(*Valid options:|(#e))}:#* :*}%% #:*}/ (arg|ARG)/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(–$match[2])-    $match[1]$match[3] (-$match[1])–$match[2]$match[3]}

改为

${=${${${(M)${(f)”$(LC_ALL=C _call_program options svn help $cmd)”#(*Valid options:|(#e))}:#* :*}%% #:*}/ (arg|ARG)/:arg:}/(#b)(-##)([[:alpha:]]##) \[--([a-z-]##)\](:arg:)#/(-    -$match[3])$match[1]$match[2]$match[4] ($match[1]$match[2])–$match[3]$match[4]}

 

参考资料:

http://www.zsh.org/mla/workers/2011/msg01448.html

解决fcitx 4.1 选择候选词后输入框消失的问题

fcitx更新到4.0之后我就一直在用fcitx,但是自2011年9月5日更新到4.1.0-1之后,很多候选词就无法上屏了,尤其是当候选词是处在第二页的时候。具体表现为当选择一个无法输入的词时输入框就会消失。后来我把这个问题报给了fcitx的开发人员,以下贴上问题解决的过程。

Issue地址是:http://code.google.com/p/fcitx/issues/detail?id=429

Reported by hess…@gmail.com, Yesterday (25 hours ago)
如何重现?
1. 输入 shishi
2. 翻页找到"实时"两个字
3. 按下对应数字键

这个时侯你会发现输入框消失了,但是当你再尝试输入其他内容时之前输入的文字又会出现在输入框里。

Fcitx 版本: 4.1.0-1
来源: Archlinux pacman
操作系统:Archlinux
桌面环境:Openbox

Comment 1 by hess…@gmail.com, Yesterday (25 hours ago)

实时是其中一个例子,如果无法重现请尝试其他词组,出现在第二页的字词在我这里基本上都无法输入。
Comment 2 by project member wen…@gmail.com, Yesterday (24 hours ago)

你是不是在用sunpinyin而没有用sunpinyin-git?

Comment 3 by hess…@gmail.com, Today (8 hours ago)

我根本就没装sunpinyin呢,只有fcitx
Comment 4 by project member wen…@gmail.com, Today (8 hours ago)

无法重现你的问题。移除配置能解决你的问题吗?

Comment 5 by hess…@gmail.com, Today (97 minutes ago)

非常遗憾,我将~/.config/fcitx 重命名为 ~/.config/fcitx.bak之后重新启动,问题依旧。

基本上只要选择的是第二页的字词候选框就会消失。
Comment 6 by project member wen…@gmail.com, Today (88 minutes ago)

我这里所有的输入法都没办法重现你的问题(码表,拼音,sunpinyin,googlepinyin)
即使是重新安装源内提供的4.1.0都没办法重现。

我怀疑你对问题的描述有不准确的地方(假设存在这个bug的话)。
如果你能把这个问题录下来就最好了。

Comment 7 by hess…@gmail.com, Today (67 minutes ago)

非常感谢你的耐心回答,我刚才又测了一下,如果我pkill fcitx,然后再从命令行通过fcitx&来启动,居然就一点问题也没有。

不知道是不是跟什么变量之类的有关系呢?

还有我再次pkill fcitx之后X就挂掉了,点啥都没反应。

我把fcitx启动的输出导了出来,你看看是否有异常?
fcitx.log
3.2 KB   View   Download
Comment 8 by project member wen…@gmail.com, Today (49 minutes ago)

其实我应该再问问你具体输入的程序是什么……按照我的推测,如果是输入很诡异的话,很可能是这个程序本身输入支持的问题,但是在某种情况下这个问题可以由fcitx绕过或者怎么样。

不过即使我用xim的话在gtk或者qt程序(甚至开启了新加入的xim的on the spot支持,这个选项默认关闭),也都没有试验出问题。

输出里面有一个dbus相关的问题,不过fcitx那个问题会进行数次连接尝试,看起来是绕过了这个问题才对。

有个相关的你也不妨参考,虽然和fcitx无关,但是也是dbus的启动问题。
https://bbs.archlinux.org/viewtopic.php?id=115474

既然你已经升级到4.1.0了
不妨把 fcitx-gtk2 ( fcitx-gtk3 fcitx-qt 如果你有需要 ) 装上,并且设置
GTK_IM_MODULE=fcitx ,而不是你以往设置的xim。

当然你更加不妨用openbox的自动启动来启动fcitx(也许这样就解决了),而不是写自己的~/.xinitrc

Comment 9 by hess…@gmail.com, Today (moments ago)

我照你的方法做了之后依然没有效果。

不过好消息是我尝试加上参数 -s 把delay设成5之后就正常了。

我现在的配置:
安装了 fcitx-gtk2 + fcitx-qt
变量写在 ~/.xprofile
export XMODIFIERS="@im=fcitx"
export GTK_IM_MODULE="fcitx"
export QT_IM_MODULE="fcitx"

启动写在 ~/.config/openbox/autostart.sh
fcitx -d -s 5 

现在看来没有发现什么问题。

非常感谢你的帮助

WEB开发的福音阿,再也不用为频繁切换host苦恼了

刚刚发现一个霸气的 Firefox 插件 HostAdmin,地址在下面有
https://addons.mozilla.org/zh-CN/firefox/addon/hostadmin/

这个插件可以分析你的hosts文件,自动在firefox中提供给你选择你需要指向的IP地址,你也可以手工修改hosts文件,安装了这个插件之后hosts的修改是实时生效的。

另外说一下,因为Firefox 4以上默认隐藏了扩展工具栏,所以安装后可能需要按CTRL+/才能在底部把它显示出来哦。

如果不会用,可以看我下面的实例:

我们有一个网站 www.test.com

我们有2个测试的ip地址

那么我们在hosts里可以这么写

#192.168.18.1 www.test.com
#192.168.18.2 www.test.com

这样当你访问www.test.com的时候,你通过点击HostAdmin就可以方便的在两个IP之间进行切换,如果不希望通过hosts直接走DNS解析的话直接再点一下当前选中的条目,去掉选中状态可以了,这时候插件会显示为“In Hosts”。 对于在hosts文件中没有的域名,插件会显示Not in Hosts。

另外附上让WIN7/Linux开放修改hosts权限的方法:
http://code.google.com/p/fire-hostadmin/wiki/GAIN_HOSTS_WRITE_PERM

JavaME常用小技巧集合[持续补充中]

1. 绘制图像缓冲区

Image img = Image.createImage( width, height );
canvs.paint( img.getGraphics() );

 


 

2. 绘制透明图案、色块

int [] argb = new int[width * height];
for ( int i = 0; i < argb.length; i++ ) {
argb[i] = 0x99000000; // ARGB
}
graphics.drawRGB(argb, 0, width, 0, 0, width, height, true);

 


 

3. Netbeans中Java(TM) Platform Micro Edition SDK 3.0的存储目录在哪里?

DefaultCldcPhone1:

C:\Documents and Settings\[USERNAME]\javame-sdk\3.0\work\6\appdb\filesystem\root1

[转]Linux 中的键盘映射

原文地址:http://www.linuxidc.com/Linux/2011-04/35197.htm

 

对于英语来说,键盘上的字母键直接和英语字母表中的字母对应,但是对于非英语的语种来说,情况就不太一样了。例如,德语中的“ß”字母就没有直接的键和它对应,为此,Linux 提供“键盘映射”或“键盘翻译”,利用键盘映射可将某些键转换为特殊键。

前面提到,X Window 直接处理了键盘的输入输出端口,因此,在 Linux 虚拟控制台下和 X Window 下使用不同的键盘映射方法。在 Linux 虚拟控制台上,可利用 loadkeys 命令将特殊按键映射为特殊字符;而在 X Window 中,必须使用 xmodmap 命令完成键盘映射。这些命令均按照字符映射表文件(文本文件)中的规定完成相应的转换。在 X Window 启动时,它会参考 Linux 文本模式下的字符映射表,因此可获得某些一致的键映射。

字符映射表文件保存在 /usr/lib/kbd/keytables 目录下,defkeymap.map 是默认的字符映射表文件。利用命令:

$ loadkeys fr.map

可装入 fr.map 所规定的字符映射表。这时,按下“.”会显示“:”。命令

$ loadkeys –d

可装入默认字符映射表。对于非默认的键盘映射,可在启动时在 shell 脚本中装入特殊的映射表。

对X Window 而言,它对键盘的处理过程分如下两个步骤:

1.X Server 首先将键码转换为键符号名(keysym)。文件 /usr/include/X11/keysymdef.h 中包含所有的符号名。X Server 能够区分修饰键带来的不同,因为 keysymdef.h 中区分了两种不同的键,例如对“a”和“A”,分别用“KS_a”和“KS_A”定义。

2.X Server 将键符号翻译为 ASCII 字符串。对于大多数的键来说,该字符串只包含一个字符,而对于功能键等特殊按键来说,则包含多个字符。例如,F5 键对应的默认 ASCII 字符串为 “5~”。

利用 xmodmap 工具可修改键盘和键符号名之间的对应关系。例如,X Window 中“A”的键码为 30,而“Q”的键码为16。如果建立文件 maptest:

keycode 38 = A

keycode 24 = Q

在 xterm 中运行

$ xmodmap maptest

之后,将发现“A”键和“Q”键交换了过来。

上述的 maptest 文件实际就是一个简单的 X Window 映射文件。但需要注意的是,文件中的 keycode 和 Linux 内核对键值的定义是不一样的,一般而言,X Window 中的键码要比内核的键值大 8。利用 showkey 命令可以查看内核对键值的定义。例如,运行 showkey 并前后按下“A”和“Q”后,程序的输出为:

$ showkey
kb mode was RAW

keycode 30 press
keycode 30 press
keycode 16 press
keycode 16 press
该程序给出的是“A”和“Q”的内核键值。
在 XF86Config 文件中,Keyboard 段用来指定键盘参数,一般而言,这些参数不需要特殊设置:
Section “Keyboard”
Protocol    “Standard”
AutoRepeat 500 5
EndSection

[译]如何在Linux下禁用键盘、触摸板、鼠标等输入设备

原文地址:http://blog.yjl.im/2010/12/using-xinput-to-disable-keyboard-mouse.html

我最近发现可以用 xinput 来禁用/启用输入设备。我经常用 synclient 来关掉我的触摸板, 或者用 xinput 来关闭我的笔记本键盘。

第一步我们需要先拿到设备的名字或者ID:

$ xinput list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ USB Optical Mouse                         id=8    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=7    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Power Button                              id=10   [slave  keyboard (3)]
    ↳ Video Bus                                 id=11   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=6    [slave  keyboard (3)]

在这里触摸板的名字是 'SynPS/2 Synaptics TouchPad' ID是 7;
键盘的名字是 'AT Translated Set 2 keyboard' ID是 6.

下一步我们要知道设备都有什么属性:

$ xinput list-props 'AT Translated Set 2 keyboard'
Device 'AT Translated Set 2 keyboard':
        Device Enabled (127):   1

键盘只有一个属性 'Device Enabled' 他的值是 1,意思就是说键盘是打开状态的。

我们来尝试关掉它:

sleep 0.1 ; xinput set-prop 'AT Translated Set 2 keyboard' 'Device Enabled' 0 ; sleep 5 ; xinput set-prop 'AT Translated Set 2 keyboard' 'Device Enabled' 1

开头 sleep 0.1 的目的是要留出时间让你执行当前命令时所敲的回车的按键(keypress)事件能够完成, 我猜测当你按下回车时命令就会执行并把键盘禁用,但是按键弹起(keyup)还没有被发送,所以X会以为你一直按这回车键。

另一个更简单的用法是用ID来进行操作,这样你就不需要输入一大长串的名字了:

sleep 0.1 ; xinput set-prop 8 127 0 ; sleep 5 ; xinput set-prop 8 127 1

键盘的ID是8, 属性 'Device Enabled' 的ID是127。 当你用 list-props 列出设备属性时, 在属性名后面的数字就是属性的ID。 像 'Device Enabled' 的ID总是 127,但是设备的ID就不一样,它跟设备的连接时间有关,一般越先连接的设备ID越小,之后会越来越大。

PS:设置设备属性不需要root权限。

又想烧键盘了。。。Noppoo Choc Mini 84

最近又想烧个新键盘了。。。

当然现在老婆卡的比较紧。。。也就烧点便宜的了。。。。

现在看中了Noppo 的 Mini84, 65%的键盘,84键,比较适合作为笔记本键盘的替代品,准备搞一个放公司敲代码用

某北京卖家地址:http://item.taobao.com/item.htm?id=9176159258&