我如何在 sphinx 中使用日期之间查询 where 子句

how can i query where clause using between date in sphinx

我有这个查询:

select * from tabel where last_purchase_categories = 'flight' 
 and last_purchase_date between '2016-10-23 11:06:47' and '2016-10-23 11:06:49';

它在 sphinx 中不起作用。我使用 mysql 查询浏览器进行全文搜索。 有谁知道如何在 sphinx 中使用日期格式?

让我们试试这个

它会起作用。

SELECT count(*) FROM `tabel` 
where last_purchase_categories = 'flight' and 
    last_purchase_date between '2017-03-27 02:13:11' and '2017-03-27 02:13:20'

我想是因为last_purchase_date的数据类型是字符串。这就是为什么我不能在查询之间使用

好吧,sphinx 不能像那样进行字符串比较,至少在 between 之间是这样(假设您在字符串属性中有日期)。而且也没有 'datetime' 属性 类型。

可以把日期放在简单的数字属性中,然后做比较。

Unix 时间戳可能很方便,可以在 sphinx 配置文件中实现(使用 mysql unix_timestamp() 函数)

sql_query = SELECT ..., UNIX_TIMESTAMP(last_purchase_date) AS last_purchase_date FROM ... 
sql_attr_uint = last_purchase_date 

那么查询会是这样的

select * from tabel where last_purchase_categories = 'flight' 
 and last_purchase_date between 1477217207 and 1477217209;

大多数编程语言都有将日期转换为时间戳的便捷函数。