按日期范围过滤 Sphinx 搜索结果
我有 Widget.title、Widget.publish_ at 和 Widget.unpublish_ at。 这是一个 Rails 应用程序,正在运行thinking_sphinx,每晚索引一次。 我想找到标题中包含“foo”并已发布的所有小部件(publish _at < Time.now,unpublish _at > Time.now)。
为了使分页正常工作,我真的想在 sphinx 查询中执行此操作。 我有 'has :publish_at, :unpublish_at' 来获取属性,但是 'Widget.search("foo @publish_ at > #{Time.now}",:match _mode=>:extended' 的语法是什么?是这样的吗甚至可能吗?
I have Widget.title, Widget.publish_ at, and Widget.unpublish_ at. It's a rails app with thinking_sphinx running, indexing once a night. I want to find all Widgets that have 'foo' in the title, and are published (publish _at < Time.now, unpublish _at > Time.now).
To get pagination to work properly, I really want to do this in a sphinx query. I have
'has :publish_at, :unpublish_at' to get the attributes, but what's the syntax for 'Widget.search("foo @publish_ at > #{Time.now}",:match _mode=>:extended'? Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,很容易做到,只需确保您覆盖了索引中的时间即可:
要纯粹根据日期来获取它,需要少量的技巧,因为狮身人面像需要有界范围(x..y而不是x>) ;=y)。 最小/最大值的使用非常不优雅,但我目前不知道有什么好的方法可以解决它。
Yep, easily possible, just make sure you're covering the times in your indexes:
To pull it based purely off the dates, a small amount of trickery is required due to sphinx requiring a bounded range (x..y as opposed to x>=y). The use of min/max value is very inelegant, but I'm not aware of a good way around it at the moment.
我还没有使用过带有rails的sphinx。
但这可以通过 Sphinx API 实现。
您需要做的是在 sphinx.conf 中设置日期时间属性。
并且不要忘记在索引选择中使用 UNIX_TIMESTAMP(publish_at)、UNIX_TIMESTAMP(unpublish_at)。
I haven't used sphinx with rails yet.
But this is possible by the Sphinx API.
What you need to do is to set a datetime attribute at your sphinx.conf.
And don't forget to use UNIX_TIMESTAMP(publish_at), UNIX_TIMESTAMP(unpublish_at) at your index select.