2011-04-19 32 views
0

我爲我的搜索引擎安裝了獅身人面像,它工作的很好,但現在我試圖使用setFilter()來添加一些額外的功能,這應該允許我做WHERE/AND子句,但是每當我嘗試搜索時,它都不會返回結果。SphinxAPI SetFilter false

這是我的MySQL代碼:http://pastebin.com/gFrvKumW

這是我的sphinx.conf:http://pastebin.com/XdppZ0MG

我的PHP代碼:

<?php 
    require("sphinxapi.php"); 
    $cl = new SphinxClient(); 
    $host = "localhost"; 
    $port = 9312; 
    $index = "library"; 
    $q = "livres"; 
    $limit = 20; 
    $ranker = SPH_RANK_PROXIMITY_BM25; 
    $mode = SPH_MATCH_ALL; 
    $cl->SetServer($host, $port); 
    $cl->SetConnectTimeout(0); 
    $cl->SetMatchMode($mode); 
    $cl->SetRankingMode($ranker); 
    //$cl->SetFilter('author_id', array(1)); 
    $res = $cl->Query($q, $index); 
    die(var_dump($res)); 
?> 

如果您添加註釋行不工作了。 我不明白爲什麼

回答

0

,如果你希望能夠使用一個字段作爲過濾器,你需要將它添加在sql_attrsphinx config file所以如果你想通過作者日期編號進行篩選,你會需要增加(假設作者的ID是一個整數):

sql_query = SELECT `autors`.id, `books`.id, `books`.author_id, `books`.title, `books`.type, `authors`.name FROM `books`, `authors` WHERE `books`.author_id = `authors`.id 
sql_attr_uint = autor_id 

我希望這可以幫助,好運很多

+0

謝謝! 是否可以爲文本添加過濾器? – Roukmoute 2011-04-19 16:27:18

+0

是http://sphinxsearch.com/docs/manual-0.9.9.html#conf-sql-attr-str2ordinal – pleasedontbelong 2011-04-19 16:34:51

+0

非常感謝! – Roukmoute 2011-04-19 16:46:36