【发布时间】:2017-10-18 14:08:30
【问题描述】:
我有:
ThinkingSphinx::Index.define :new_post, with: :real_time do
indexes title, sortable: true
indexes text
has state, type: :string
has forum_hidden, type: :boolean
has created_at, type: :timestamp
has publish_at, type: :timestamp
has reminde_at, type: :timestamp
has deleted_at, type: :timestamp
has content_category_ids, type: :integer, multi: true
end
我需要获取所有记录,其中@title=query 具有任何值 publish_at 或 @text=query 具有 publish_at = 1.month.ago..Time.current
也就是说,我需要将这两个请求结合起来:
NewPost.search(conditions: { title: query })
NewPost.search(conditions: { text: query }, with: { publish_at: 1.month.ago..Time.current })
结果需要摘录
更新
@title 和@text 字段的published_at 间隔总是不同的,取决于用户的权限。比如可能有这样的情况:
NewPost.search(conditions: { title: query }, with: { publish_at: 1.year.ago..Time.current })
NewPost.search(conditions: { text: query }, with: { publish_at: 6.month.ago..Time.current })
所有不属于这些条件的结果根本不应该显示
【问题讨论】:
-
现在已经看到了编辑,您可能别无选择,只能运行两个查询,然后合并...怀疑 ts 是否具有联合功能