I have Sphinx Search installed as my search engine and I’m trying to add a few extra features to the search using setFilter() and SetSelect() which should allow me to do WHERE/AND clauses. But whenever I try a search, it returns no results instead of results.
Here is my sphinx.conf: http://pastebin.com/M6Kd71u0
And here’s the PHP code:
require("sphinxapi.php");
$host = "localhost";
$port = 9312;
$index = "llgenre";
$select1 = "cartoon";
$label6 = "children";
$type = 4;
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
$mode = SPH_MATCH_ALL;
$sphinx = new SphinxClient();
$sphinx->setServer($host, $port);
$sphinx->setConnectTimeout(0);
$sphinx->setMatchMode($mode);
$sphinx->setRankingMode($ranker);
$sphinx->setSelect('*, select1="'.$select1.'" AND label6="'.$label6.'" AS mycond');
$sphinx->setFilter('mycond', array(1));
$res = $sphinx->query($type, $index);
die(var_dump($res));
How can I search by type = 4, filter by select1 with cartoon and finally on label6 with children?
I believe what you’re attempting to do is to filter strings as attributes. Referring to the Sphinx FAQ, they outline the procedure
So, in my sphinx.conf, I might have the following…
Then in PHP, I would apply a filter on the field like so…
—
Unfortunately, PHP has an annoying problem(bug?) when converting to crc32… something involving unsigned integers or something..
I use the following function to convert correctly
—
Be careful of character case! You may choose to convert the column to lower case while indexing eg.
and searching…