Ruby on Rails 中太阳黑子的日期范围方面
我正在使用 Sunspot 在 Ruby on Rails 3 应用程序中搜索事件(聚会、音乐会等)。
我已经成功地在几个不同的类别类型上设置了自由文本搜索和构面搜索。
现在,我正忙着下一个任务。 我想设置与事件发生时间相关的方面。
我想要有描述相对日期/时间范围(例如“今天”、“本周末”、“下周末”和绝对日期/时间范围)的方面,例如“2011 年复活节假期”、“2012 年元旦”...日期时间范围有时会相互重叠。
我浏览了 Sunspot API 文档、Sunspot wiki、Stackoverflow,阅读并加载了大量文章和博客。人们正在写它是可能实现的,但我没有找到任何例子或实现想法让我理解如何做到这一点。
有什么建议吗?
由于我的问题不在我的代码中,因此我不发布任何代码。 Event 类有一个名为“start_time”的 DateTime 实例。我确实理解我的工作是定义绝对日期/时间范围何时出现在日历中。
最好的问候,
./stefan
PS 我有告诉过我是新手吗? ;-) DS
I am using Sunspot to search for events (parties, concerts, ...) in a Ruby on Rails 3 application.
I have managed to set up free text search and facet search on a couple of different category types.
Now, I am stuck with my next task. I want to set up facets related to when the event is occuring.
I want to have facets describing both relative date/time ranges such as "today", "this weekend", "next weekend" and absolute date/time ranges, such as "Easter Holiday 2011", "New Years Day 2012", ... The datetime ranges are sometimes overlapping each other.
I have browsed around in the Sunspot API documentation, the Sunspot wiki, here at Stackoverflow, read and loads of articles and blogs. People are writing it is possible to to achieve but I find no examples or implementation ideas that makes me understand how to do this.
Any suggestions?
Since my problem is not in my code, I don't publish any code. The class Event has a DateTime instance named "start_time". I do understand it's my job to define when the absolute date/time ranges appear in the calender.
Best regards,
./stefan
PS Did I tell I'm a newbie? ;-) DS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将字段设置为 trie 时间字段,以进行有效的范围查询:
然后您可以使用查询构面根据范围进行构面:
这里的关键见解是您可以使用任意范围构建构面。请注意,构面名称
:start_time
仅用于引用搜索结果中的构面,行标签:today
和:tomorrow
是类似地,仅在客户端使用来识别与这些查询相对应的行计数;从 Solr 的角度来看,它们没有任何意义,因此您可以随意称呼它们(使用您想要的任何数据类型——它们不必是符号)。有关查询方面的更多信息,请参见:http://sunspot.github。 com/docs/Sunspot/DSL/FieldQuery.html#facet-instance_method
You should set up your fields as trie time fields for efficient range queries:
Then you can use query facets to facet based on ranges:
The key insight here is that you can construct facets using arbitrary scopes. Note that the facet name
:start_time
is just used to reference the facet in the search results, and the row labels:today
and:tomorrow
are similarly just used on the client side to identify the row counts corresponding to those queries; they have no meaning from Solr's standpoint, so you can call them whatever you want (using whatever data type you want -- they don't have to be symbols).More information on query facets here: http://sunspot.github.com/docs/Sunspot/DSL/FieldQuery.html#facet-instance_method
你可以这样做:
看这里: http://sunspot.github.io /docs/Sunspot.html#search-class_method
You can do in this way:
Look here: http://sunspot.github.io/docs/Sunspot.html#search-class_method