Ruby on Rails 中太阳黑子的日期范围方面

发布于 2024-10-19 03:56:44 字数 653 浏览 8 评论 0原文

我正在使用 SunspotRuby 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里南柯 2024-10-26 03:56:45

您应该将字段设置为 trie 时间字段,以进行有效的范围查询:

class Event
  searchable do
    time :start_time, :trie => true
  end
end

然后您可以使用查询构面根据范围进行构面:

Event.search do
  facet :start_time do
    bod = Time.zone.now.beginning_of_day
    row :today do
      with :start_time, bod..(bod + 1)
    end
    row :tomorrow do
      with :start_time, (bod + 1)..(bod + 2)
    end
    # etc.
  end
end

这里的关键见解是您可以使用任意范围构建构面。请注意,构面名称 :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:

class Event
  searchable do
    time :start_time, :trie => true
  end
end

Then you can use query facets to facet based on ranges:

Event.search do
  facet :start_time do
    bod = Time.zone.now.beginning_of_day
    row :today do
      with :start_time, bod..(bod + 1)
    end
    row :tomorrow do
      with :start_time, (bod + 1)..(bod + 2)
    end
    # etc.
  end
end

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

樱花坊 2024-10-26 03:56:45

你可以这样做:

with(:registration_date).between(params[:start_date].to_date..params[:end_date].to_date)

看这里: http://sunspot.github.io /docs/Sunspot.html#search-class_method

You can do in this way:

with(:registration_date).between(params[:start_date].to_date..params[:end_date].to_date)

Look here: http://sunspot.github.io/docs/Sunspot.html#search-class_method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文