2014-01-07 82 views
0

我已經開始使用Sphinx我試圖安裝獅身人面像。一切工作正常,但我想搜索部分關鍵字。我想知道如何在網頁上顯示結果。例子:
Ex。
我搜索 ''
結果應該是: '', '更新', '晚', '' 等
我sphinx.con:Sphinx搜索:部分關鍵字

source src1 
{ 
    type   = mysql 
    sql_host  = localhost 
    sql_user  = username 
    sql_pass  = ******* 
    sql_db  = db_name 
    sql_port  = 3306 # optional, default is 3306 

    sql_query  = \ 
    SELECT id, msgtext, created \ 
    FROM agi_sms 

    sql_attr_string = msgtext 
    sql_attr_timestamp = created 

    sql_query_info  = SELECT * FROM agi_sms WHERE id=$id 

}

index test1 
    { 
    source   = src1 
    path   = C:/Sphinx/data/test1 
    docinfo   = extern 
    charset_type  = sbcs 
    enable_star = 1 
    morphology = stem_en 
    min_infix_len = 2 
    infix_fields = msgtext 
    dict = keywords 

    } 



    indexer 
    { 
     mem_limit  = 32M 
    } 


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

這是我的PHP文件:

$cl = new SphinxClient(); 
$q = $_POST['search']; 
$sql = ""; 
$mode = SPH_MATCH_EXTENDED2; 
$host = "localhost"; 
$port = 9312; 
$index = "*"; 
$groupby = ""; 
$filter = "created"; 
$filtervals = array(); 
$distinct = ""; 
$sortby = ""; 

$sortexpr = ""; 
$limit = 20; 
$ranker = SPH_RANK_PROXIMITY_BM25; 
$select = ""; 

//////////// 
// do query 
//////////// 

    $cl = new SphinxClient(); 
    $cl->SetServer("localhost", 9312); 
    $cl->SetMatchMode(SPH_MATCH_ANY); 
    $cl->SetFilter('created', array(3)); 

$res = $cl->Query ($q, $index); 
//////////////// 
// print me out 
//////////////// 

if ($res===false) 
{ 
    print "Query failed: " . $cl->GetLastError() . ".\n"; 

} else 
{ 
    if ($cl->GetLastWarning()) 
    print "WARNING: " . $cl->GetLastWarning() . "\n\n"; 

    print "<li>Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n</li>"; 
    print "<li>Query stats:\n"; 
    if (is_array($res["words"])) 
    foreach ($res["words"] as $word => $info) 
     print " '$word' found $info[hits] times in $info[docs] documents\n</li>"; 
    print "\n"; 


} 

結果:

Query 'good' retrieved 0 of 0 matches in 0.007 sec. 
Query stats: 'good' found 7534 times in 7534 documents 

但是,如果我嘗試搜索 '咕',它搜索一無所獲。

Query 'goo' retrieved 0 of 0 matches in 0.000 sec. 
Query stats: 'goo' found 0 times in 0 documents 

我想要得到的一切結果具有「」的字/字母。

這樣的:

Array(1 element) { 
    0 Object { 
     id = 1, 
     message = Good Morning 
    } 
    2 Object { 
     id = 2, 
     message = Good Day! 
    } 
} 

回答

1

$ CL->使用setfilter( '創造',陣列(3)); 你確定你有創建= 3的記錄嗎? 也爲通配符搜索你應該做'goo *'(標記*)或設置expand_keywords = 1.

+0

我有一個類似的問題,'expand_keywords = 1'是我失蹤。這允許用戶不必輸入*作爲通配符搜索。謝謝! – iJeep