基于日期时间的 Sphinx 搜索

发布于 2024-11-28 13:44:06 字数 659 浏览 0 评论 0原文

我有一个名为“createdOn”的字段,其类型为“时间戳”。其中存储的值如下: 2011-08-07 00:00:00

我想按此属性进行搜索。例如,在 mysql 中我会这样做:

SELECT * FROM `posts` where deleted = 1 and date(createdOn) = '2011-8-4'

我尝试在 sphinx 中设置它:

sql_query               = \
        SELECT id, deleted, upvotes, DATE(createdOn) as createdOn, thread_title, first_post \
        FROM posts
sql_attr_bool       = deleted
sql_attr_timestamp  = createdOn

在 php 中:

  $cl->SetFilter ( "deleted",array(1));
  $cl->SetFilter ( "createdOn", '2011-8-4');
  $result = $cl->Query("");

但这给了我一个断言失败错误。

谢谢你

I have a field called 'createdOn' which of the type 'timestamp'. The values stored in it are as such e.g.: 2011-08-07 00:00:00

I would like to search by this attribute. For example in mysql I would do this :

SELECT * FROM `posts` where deleted = 1 and date(createdOn) = '2011-8-4'

I tried to set it up in sphinx as such :

sql_query               = \
        SELECT id, deleted, upvotes, DATE(createdOn) as createdOn, thread_title, first_post \
        FROM posts
sql_attr_bool       = deleted
sql_attr_timestamp  = createdOn

and in php:

  $cl->SetFilter ( "deleted",array(1));
  $cl->SetFilter ( "createdOn", '2011-8-4');
  $result = $cl->Query("");

But this gives me an assertion failed error.

Thanking you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏见 2024-12-05 13:44:06

属性时间戳应该具有整数值。

在 sphinx.conf 中:

sql_query = select UNIX_TIMESTAMP(createdOn) as createdOn from ...
sql_attr_timestamp = createdOn

和 php 中:

$cl->SetFilter ( "createdOn", strtotime('2011-8-4'));
$result = $cl->Query("");

Attribute timestamp should have integer value.

In sphinx.conf:

sql_query = select UNIX_TIMESTAMP(createdOn) as createdOn from ...
sql_attr_timestamp = createdOn

and in php:

$cl->SetFilter ( "createdOn", strtotime('2011-8-4'));
$result = $cl->Query("");
凉墨 2024-12-05 13:44:06

对于较新版本的 Sphinx,您需要使用 SetFilterRange , IE:

$createdOn = strtotime('2011-8-4');
$cl->SetFilterRange("createdOn", $createdOn, $createdOn + 86400);

For newer versions of Sphinx you need to use SetFilterRange, i.e.:

$createdOn = strtotime('2011-8-4');
$cl->SetFilterRange("createdOn", $createdOn, $createdOn + 86400);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文