0

我在我的 WIN XP 中安装了 sphinx,我不知道我是否安装成功。sphinx的配置文件内容如下,位置是f:/sphinx/sphinx.conf。

我的环境是:
1)sphinx 的目录:f:/sphinx/,配置文件的路径:f:/sphinx/shpinx.conf
2)数据库:tbdb.ratedat。sphinx 版本:sphinx-for-chinese-2.1.0-dev-r3361-win32.zip
3) Apache/2.4.4(win32) PHP/5.4.16,MYSQL 版本:5.6.12

source srcDB
{
    type            = mysql

    sql_host        = localhost
    sql_user        = root
    sql_pass        = zbphp.com~$
    sql_db          = tbdb
    sql_port        = 3306

    sql_query_pre   = SET NAMES utf8
    #sql_query_pre   = SET SESSION query_cache_type=OFF

    sql_query       = \
        SELECT trade_id,trade_time,goods_title,goods_price,uid_buy,uid_sell \
        FROM ratedat

    sql_attr_bigint     = trade_id
    sql_attr_bigint     = uid_buy
    sql_attr_bigint     = uid_sell
    sql_attr_timestamp  = trade_time
    sql_attr_string     = goods_title
    sql_attr_string     = rate_txt

    sql_query_info      = SELECT * FROM ratedat WHERE trade_id=$id
}


index goods_title
{
    source  =   srcDB
    path    =   F:/sphinx/data/ratedat.goods_title
    charset_type    =   utf-8
    html_strip      = 1
}


indexer
{
    mem_limit       = 128M
}


searchd
{
    listen          = 9312
    listen          = 9306:mysql41
    log         = F:/sphinx/log/searchd.log
    query_log       = F:/sphinx/log/query.log
    read_timeout        = 5
    max_children        = 30
    pid_file        = F:/sphinx/log/searchd.pid
    max_matches     = 1000
    seamless_rotate     = 1
    preopen_indexes     = 1
    unlink_old      = 1
    workers         = threads # for RT to work
    binlog_path     = F:/sphinx/data
}

我的安装bat文件
路径:f:/sphinx/install.bat
代码:如下

net stop SphinxSearch
sc delete SphinxSearch
del /s/q %cd%\log\*.*
del /s/q %cd%\data\*.*

%cd%\bin\searchd --install --config %cd%\sphinx.conf --servicename SphinxSearch
%cd%\bin\indexer -c %cd%\sphinx.conf --all

net start SphinxSearch
pause


运行 install.bat 时输出消息

F:\sphinx>net stop SphinxSearch
SphinxSearch 服务正在停止..
SphinxSearch 服务已成功停止。


F:\sphinx>sc delete SphinxSearch
[SC] DeleteService SUCCESS

F:\sphinx>del /s/q F:\sphinx\log\*.*
delfile - F:\sphinx\log\query.log
delfile - F:\sphinx\log\searchd.log

F:\sphinx>del /s/q F:\sphinx\data\*.*
delfile - F:\sphinx\data\binlog.001
delfile - F:\sphinx\data\binlog.meta
delfile - F:\sphinx\data\ratedat.goods_title.spa
delfile - F:\sphinx\data\ratedat.goods_title.spd
delfile - F:\sphinx\data\ratedat.goods_title.spe
delfile - F:\sphinx\data\ratedat.goods_title.sph
delfile - F:\sphinx\data\ratedat.goods_title.spi
delfile - F:\sphinx\data\ratedat.goods_title.spk
delfile - F:\sphinx\data\ratedat.goods_title.spm
delfile - F:\sphinx\data\ratedat.goods_title.spp
delfile - F:\sphinx\data\ratedat.goods_title.sps

F:\sphinx>F:\sphinx\bin\searchd --install --config F:\sphinx\sphinx.conf --servi
cename SphinxSearch
sphinx-for-chinese 2.1.0-dev (r3361)
Copyright (c) 2008-2012, sphinx-search.com

Installing service...
Service 'SphinxSearch' installed succesfully.

F:\sphinx>F:\sphinx\bin\indexer -c F:\sphinx\sphinx.conf --all
sphinx-for-chinese 2.1.0-dev (r3361)
Copyright (c) 2008-2012, sphinx-search.com

using config file 'F:\sphinx\sphinx.conf'...
indexing index 'goods_title'...
WARNING: attribute 'trade_id' not found - IGNORING
WARNING: source srcDB: skipped 10378355 document(s) with DOCID_MAX ids
collected 176464 docs, 12.1 MB
sorted 0.7 Mhits, 100.0% done
total 176464 docs, 12144715 bytes
total 37.745 sec, 321754 bytes/sec, 4675.12 docs/sec
total 2 reads, 0.007 sec, 4604.6 kb/call avg, 3.9 msec/call avg
total 19 writes, 0.360 sec, 950.7 kb/call avg, 18.9 msec/call avg

F:\sphinx>net start SphinxSearch
SphinxSearch starting... 
SphinxSearch start successed


F:\sphinx>pause
please press any key to continue. . .

我的 php 脚本的内容如下,但结果为空。

<?php

require ( "sphinxapi.php" );

$s = new SphinxClient();
$s->SetServer('localhost');
$rst = $s->Query('电脑');
print_r($s);
print_r($rst);

/*
SphinxClient Object
(
    [_host] => localhost
    [_port] => 9312
    [_offset] => 0
    [_limit] => 20
    [_mode] => 0
    [_weights] => Array
        (
        )

    [_sort] => 0
    [_sortby] => 
    [_min_id] => 0
    [_max_id] => 0
    [_filters] => Array
        (
        )

    [_groupby] => 
    [_groupfunc] => 0
    [_groupsort] => @group desc
    [_groupdistinct] => 
    [_maxmatches] => 1000
    [_cutoff] => 0
    [_retrycount] => 0
    [_retrydelay] => 0
    [_anchor] => Array
        (
        )

    [_indexweights] => Array
        (
        )

    [_ranker] => 0
    [_rankexpr] => 
    [_maxquerytime] => 0
    [_fieldweights] => Array
        (
        )

    [_overrides] => Array
        (
        )

    [_select] => *
    [_error] => 
    [_warning] => 
    [_connerror] => 
    [_reqs] => Array
        (
        )

    [_mbenc] => 
    [_arrayresult] => 
    [_timeout] => 0
    [_path] => 
    [_socket] => 
)
Array
(
    [error] => 
    [warning] => 
    [status] => 0
    [fields] => Array
        (
            [0] => goods_title
            [1] => goods_price
        )

    [attrs] => Array
        (
            [trade_time] => 2
            [uid_buy] => 6
            [uid_sell] => 6
        )

    [total] => 0
    [total_found] => 0
    [time] => 0.000
)

*/
4

1 回答 1

0

http://sphinxsearch.com/forum/view.html?id=11468

怀疑这是个charset_table问题。由于在当前设置中实际上不包括中文字符。

于 2013-09-09T11:29:54.100 回答