2016-05-22 167 views
0

我很困惑Sphinx。我說這個問題。
我的系統配置:爲什麼Sphinxapi不返回結果?

  • Ubuntu 16.04 LTS
  • Apache 2.4.18
  • PHP 5.6.21
  • MariaDB 10.1.14
  • sphinx 2.2.10

我的數據庫是test2,它包含2個表(文檔和用戶)和1查看(搜索)。

  • 文件(表):

    • ID
  • 用戶(表):

    • ID
    • fname
    • lname
    • 電子郵件
  • 搜索(視圖):

    • sphinxid
    • itemid
    • 數據
    • datatype

搜索視圖查詢是

CREATE ALGORITHM = UNDEFINED DEFINER = root @localhost SQL SECURITY DEFINER VIEW search AS SELECT UUID_SHORT()AS sphinxidusersid AS itemid, CONCAT_WS(」」, usersfnameuserslnameusersemail)AS data, 1 AS datatype FROM users UNION SELECT UUID_SHORT()AS sphinxiddocumentsid AS itemid, documentsname AS data, 2 AS datatype FROM documents

斯芬克斯配置文件:

source my_search 
{ 
     type     = mysql 

     sql_host    = localhost 
     sql_user    = root 
     sql_pass    = myPass 
     sql_db     = test2 
     sql_port    = 3306 # optional, default is 3306 

     sql_query    = \ 
       SELECT sphinxid,itemid, data, datatype \ 
       FROM test2.search; 


     sql_attr_uint   = itemid 
     sql_attr_uint   = data 
} 

index test1 
{ 
     source     = my_search 
     path     = /var/lib/sphinxsearch/data/test1 
     morphology    = stem_en 

     min_word_len   = 3 
     # min_prefix_len   = 0 
     # enable_star    = 0 
} 

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

我用這個命令,以使索引indexer --config /etc/sphinxsearch/sphinx.conf --all --rotate。其結果是:

Sphinx 2.2.10-id64-release (2c212e0) 
Copyright (c) 2001-2015, Andrew Aksyonoff 
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com) 

using config file '/etc/sphinxsearch/sphinx.conf'... 
indexing index 'test1'... 
collected 200 docs, 0.0 MB 
total 200 docs, 200 bytes 
total 0.007 sec, 28417 bytes/sec, 28417.16 docs/sec 
total 2 reads, 0.000 sec, 1.5 kb/call avg, 0.0 msec/call avg 
total 10 writes, 0.000 sec, 0.6 kb/call avg, 0.0 msec/call avg 
rotating indices: successfully sent SIGHUP to searchd (pid=2287). 

我用sphinxapi.php爲客戶api和我php測試文件是:

<?php 

include '../sphinxapi.php'; 

if(!empty($_GET['q'])){ 
    var_dump($_GET['q']); 
    // Build search query 
    $cl = new SphinxClient(); 
    $cl->SetServer("localhost", 9312); 
    $cl->SetMatchMode(SPH_MATCH_EXTENDED ); 
    $cl->SetRankingMode (SPH_RANK_SPH04); 
    // Execute the query 
    $q = '"' . $cl->EscapeString($_GET['q']) . '"/1'; 
    $searchresults = $cl->Query($q ,'test1'); 
    var_dump($cl->GetLastError()); 
    var_dump($cl->GetLastWarning()); 
} 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Sphinx test 1</title> 
</head> 

    <body> 
     <form name="search" method="get" action=""> 
      <input type="text" name="q" id="q" /> 
      <input type="submit" value="GO" class="form-submit" /> 
     </form> 
     <p> 
      <pre> 
       <?php 
       if(!empty($searchresults)){ 
        print_r($searchresults); 
       } 
       ?> 
      </pre> 
     </p> 
    </body> 

</html> 

我看search view和我選擇一個領域(Scarlett [email protected]),但是當我搜索它(有點像「血色」),我沒有得到任何結果:

Array 
(
    [error] => 
    [warning] => 
    [status] => 0 
    [fields] => Array 
     (
      [0] => datatype 
     ) 

    [attrs] => Array 
     (
      [itemid] => 1 
      [data] => 1 
     ) 

    [total] => 0 
    [total_found] => 0 
    [time] => 0.000 
    [words] => Array 
     (
     [scarlet] => Array 
      (
       [docs] => 0 
       [hits] => 0 
      ) 

    ) 
) 

真的,我不知道爲什麼它retur什麼都沒有?


我使用這個命令mysql -h0 -P9306根據獅身人面像tutorial.you可以在圖片中看到,我沒有任何數據(你可以看到我在sphinx.conf查詢),並返回20行!(用戶表中有100行和文檔表有90行)。 <code>mysql -h0 -P9306</code> result

我使用本教程Integrating Sphinx Search into a PHP Application但我無法在我的應用程序中得到結果! :(


當我使用默認sphinx.conf及其測試數據庫,我的應用程序works.I覺得我sphinx.conf是錯誤的或者也許我的觀點(搜索)引起的!

回答

1

在查詢尋找

SELECT sphinxid,itemid, data, datatype \ 
      FROM test2.search; 

依次以各

  • sphinxid - >自動document_id(第一列)
  • 的itemid - >製成uint attribute(由於sql_attr_uint)
  • 數據 - >製成uint attribute(由於sql_attr_uint)
  • 數據類型 - 未提及,所以文本field

但是,你的觀點

... CONCAT_WS(' ', users.fname, users.lname, users.email) AS data, 
1 AS datatype ... 

所以看起來像你的實際文本是在「數據」,然後將其存儲在一個整數屬性。不工作!

:建議

sql_attr_uint   = data 

是筆誤,應該是

sql_attr_uint   = datatype 

呢? (將數據作爲文本字段編入索引!)

相關問題