【问题标题】:thinking_sphinx nested date searchthinking_sphinx 嵌套日期搜索
【发布时间】:2012-07-13 13:54:49
【问题描述】:

假设我有以下场景:

class Conference < ActiveRecord::Base
    has_many :meetings

    define_index do
        # index
    end
end

class Meeting < ActiveRecord::Base
    belongs_to :conference

    validates_presence_of :start_time
    validates_presence_of :end_time
end

我想根据开始时间搜索会议,所以当我提供开始时间时,它会返回给我的会议列表,这些会议在提供的时间之后仍然有一个或多个会议的开始时间。 Thinking_sphinx 有可能吗?至少,我应该如何定义我的索引?

编辑

需要搜索会议(即 Conference.seacch)

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 thinking-sphinx


    【解决方案1】:
    class Meeting < ActiveRecord::Base
     belongs_to :conference
    
     ..
     define_index do
        indexes :start_time
        has conference_id
      end
    end
    

    然后

    Meeting.search :conditions => {:created_at => 1.week.ago..Time.now}
    

    http://freelancing-god.github.com/ts/en/indexing.html

    http://freelancing-god.github.com/ts/en/searching.html

    【讨论】:

    • 这是有道理的,但在这种情况下,我们搜索的是会议,而不是会议。是否可以通过在会议模型上的搜索来实现?
    • 你打算如何从会议开始搜索会议开始时间?您只需重新路由将在会议表中搜索。 "Meeting.* where meeting_id=x" 您要搜索的列需要存在于您要使用 .search 的模型中
    • 我猜是这样。毕竟,将索引移动到 Metting 模型是可行的。
    猜你喜欢
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-13
    相关资源
    最近更新 更多