Php 使用文本/字符串值在Sphinx中创建过滤器

Php 使用文本/字符串值在Sphinx中创建过滤器,php,sphinx,Php,Sphinx,我安装了Sphinx Search作为我的搜索引擎,我正在尝试使用setFilter()和SetSelect()为搜索添加一些额外的功能,这应该允许我执行WHERE/and子句。但每当我尝试搜索时,它都不会返回结果而不是结果 这是我的sphinx.conf: 下面是PHP代码: require("sphinxapi.php"); $host = "localhost"; $port = 9312; $index = "llgenre"; $select1 = "cartoon"; $label

我安装了Sphinx Search作为我的搜索引擎,我正在尝试使用
setFilter()
SetSelect()
为搜索添加一些额外的功能,这应该允许我执行
WHERE/and
子句。但每当我尝试搜索时,它都不会返回结果而不是结果

这是我的sphinx.conf:

下面是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
使用
children
进行过滤?

我相信您尝试的是将字符串作为属性进行过滤。他们在参考第二部分时概述了程序

如何按筛选、排序或分组 不带字符串的字符串列 属性

你可以做所有这些,除了 精确的任意长度排序 几个索引

要进行筛选和分组,可以替换 具有唯一数字ID的字符串。 有时,创建一个 在数据库中查找字典(例如。 用于固定的城市或城市列表 国家),甚至使用现有的 第一,用字符串中的ID替换字符串 该字典,然后进行筛选和分组 在该ID上。如果没有,您总是可以 将字符串替换为其校验和, 例如,CRC32()或(任何)64位 在索引时从MD5()开始(无需 要更改表!),请使用 sql\u attr\u uint或sql\u attr\u bigint 分别,然后过滤或分组 在该校验和属性上。(注意 有一定的可能是CRC32() 如果你有数百万 但几乎没有机会 MD5()冲突。)

因此,在我的sphinx.conf中,我可能有以下内容

sql_query = SELECT CRC32(string_field) AS `string_field` FROM `table`

sql_attr_uint = string_field
然后在PHP中,我会在字段上应用一个过滤器,如下所示

$sphinx->SetFilter('string_field', array(crc32( 'filter_string' ));
--

不幸的是,PHP在转换为crc32时有一个恼人的问题(bug?)。。。涉及无符号整数或其他东西的东西

我使用以下函数来正确转换

class Encode {
    public static function crc32($val){
        $checksum = crc32($val);
        if($checksum < 0) $checksum += 4294967296;
        return $checksum;
    }
}
搜索

$sphinx->SetFilter('string_field', array(crc32(strtolower( 'Filter_String' )));

非常感谢你的回答,虽然已经很晚了。所以我找到了同样的答案,还有一段时间。我接受了你的答复,因为这正是我为之奋斗了几天的事情——这真是一个伟大的解决方案。非常感谢。
$sphinx->SetFilter('string_field', array(crc32(strtolower( 'Filter_String' )));