开发者

SphinxAPI SetFilter false

开发者 https://www.devze.com 2023-02-26 19:14 出处:网络
I have sphinx installed for my search engine, and it works great, but now I\'m t开发者_如何学JAVArying to add a few extra features to the search using setFilter() which should allow me to do WHERE/AND

I have sphinx installed for my search engine, and it works great, but now I'm t开发者_如何学JAVArying to add a few extra features to the search using setFilter() which should allow me to do WHERE/AND clauses, but whenever I try a search, it returns no results when there should.

This is my MySQL Code : http://pastebin.com/gFrvKumW

This is my sphinx.conf : http://pastebin.com/XdppZ0MG

And my PHP code :

<?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));
?>

if you add the commented line is not working anymore. I do not understand why


if you want to be able to use a field as a filter, you'll need to add it in the sql_attr on your sphinx config file so if you want to filter by autor id, you'll need to add (assuming that the author's id is an integer):

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

i hope this helps, Good Luck

0

精彩评论

暂无评论...
验证码 换一张
取 消