在 Sphinx 中使用文本/字符串值创建过滤器
我安装了 Sphinx Search 作为我的搜索引擎,并且我正在尝试使用 setFilter()
和 SetSelect()
向搜索添加一些额外的功能,这应该允许我执行 WHERE/AND
子句。但每当我尝试搜索时,它都会返回任何结果而不是结果。
这是我的 sphinx.conf: http://pastebin.com/M6Kd71u0
这是 PHP 代码:
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));
我怎样才能按 type = 4
搜索,按 select1
和 cartoon
过滤,最后按 label6
过滤孩子
?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您尝试做的是将字符串作为属性进行过滤。他们参考 Sphinx 常见问题解答,概述了该过程
所以,在我的 sphinx.conf 中,我可能有以下内容...
然后在 PHP 中,我会像这样在字段上应用过滤器...
--
不幸的是,PHP 有一个恼人的问题(bug ?)当转换为crc32时...涉及无符号整数或其他内容的东西..
我使用以下函数来正确转换
--
小心字符大小写!您可以选择在索引时将列转换为小写,例如。
并寻找...
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...