思考狮身人面像日期范围问题
为什么这会返回结果:
@results = Index.search "#{@keywords}", :with => {
:published_on => 1.week.ago..Time.now,
}
而不是 this?
@results = Index.search "#{@keywords}", :with => {
:published_on => '2011-04-01'..'2011-04-08',
}
published_on
是一个日期时间字段,但我也尝试过使用小时、分钟和秒。
Why does this return results:
@results = Index.search "#{@keywords}", :with => {
:published_on => 1.week.ago..Time.now,
}
but not this?
@results = Index.search "#{@keywords}", :with => {
:published_on => '2011-04-01'..'2011-04-08',
}
published_on
is a datetime field, but I have tried it with hour, minutes and seconds as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于您得到了结果,我猜
published_on
实际上是一个属性,而不是一个字段?如果属性是日期时间数据类型,那么您需要为过滤器传递 Ruby Time 对象 - 即整数时间戳(这就是 Thinking Sphinx 将时间转换为的值)。 TS 不会尝试解析字符串,因此您需要自己管理。
在自动解析日期和时间方面,Sphinx 并不像 MySQL 那样精美 - 您需要使用正确的数据类型。
Given you're getting results, I'm guessing
published_on
is actually an attribute, not a field?If the attribute is a datetime data type, then you need to pass in Ruby Time objects for filters - that, or integer timestamps (which is what Thinking Sphinx converts times to anyway). TS doesn't try to parse strings, so you'll need to manage that yourself.
Sphinx isn't as fancy as MySQL when it comes to auto-parsing dates and times - you need to use the right data type.