我有一个名为' 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("");
但是这给了我一个断言失败的错误。
感谢你
答案 0 :(得分:4)
属性时间戳应该具有整数值。
在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("");
答案 1 :(得分:1)
对于较新版本的Sphinx,您需要使用SetFilterRange
,即:
$createdOn = strtotime('2011-8-4');
$cl->SetFilterRange("createdOn", $createdOn, $createdOn + 86400);