在 Sphinx 中搜索哈希码

Search on the hash code in Sphinx

我在数据库中有一个这种类型的哈希码:b67583fad7ccc238a34eacfcdc16bfd8557cc82f 它们都是40个字符。 从数据库中我得到 ids:

SELECT id FROM `table` WHERE info_hash=UNHEX('b67583fad7ccc238a34eacfcdc16bfd8557cc82f')

SELECT from MySql whitout UNHEX() 不起作用。所以我使用 UNHEX().

从 Sphinx 我试过:

$cl->SetFilter('info_hash',array('UNHEX("b67583fad7ccc238a34eacfcdc16bfd8557cc82f")'));

等等

$cl->SetFilter('info_hash',array('HEX(UNHEX("b67583fad7ccc238a34eacfcdc16bfd8557cc82f"))'));

即便如此

$result = $cl->Query('@info_hash "'.bin2hex("b67583fad7ccc238a34eacfcdc16bfd8557cc82f").'"',$index_name);

Sphinx 配置:

sql_query = SELECT id,info_hash,name,cast FROM table_name
sql_field_string = name
sql_field_string = info_hash
sql_field_string = cast

对于现场演员,我得到的 id 是这样的:

$result = $cl->Query('@cast "Brad Pitt"',$index_name);

一切正常,但 info_hash 不行。我做错了什么?

$cl->SetFilter('info_hash',array('UNHEX("b67583fad7ccc238a34eacfcdc16bfd8557cc82f")'));

不起作用,因为 setFilter 采用整数数组。另外不清楚你认为谁会执行 'UNHEX' 函数,记住它是一个 mysql 函数!


php 确实有一个 hex2bin 函数(相当于 UNHEX()),所以或许可以使用它。

当您将散列放入字符串属性时,也许可以使用

$cl->SetFilterString('info_hash',hex2bin("b67583fad7ccc238a34eacfcdc16bfd8557cc82f"));

请务必正确设置集合,以便您的 binary 字符串得到妥善保存。 http://sphinxsearch.com/docs/current.html#collations

(你也有一个字段,但很难匹配,因为它与 charset_table 标记化一起使用,所以你的编码二进制字符串不太可能存活到正确的标记中)