Sphinx 斯芬克斯思维中不同领域的不同条件

Sphinx 斯芬克斯思维中不同领域的不同条件,sphinx,thinking-sphinx,Sphinx,Thinking Sphinx,我有: 我需要得到所有的记录,其中@title=query的值为publish\u at,或者@text=query的值为publish\u at=1.month.ago..Time.current 也就是说,我需要将这两个请求结合起来: ThinkingSphinx::Index.define :new_post, with: :real_time do indexes title, sortable: true indexes text has state, type: :st

我有:

我需要得到所有的记录,其中@title=query的值为publish\u at,或者@text=query的值为publish\u at=1.month.ago..Time.current

也就是说,我需要将这两个请求结合起来:

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和@text字段的发布间隔总是不同的,取决于用户的权限。例如,可能存在这样的情况:

NewPost.search(conditions: { title: query })
NewPost.search(conditions: { text: query }, with: { publish_at: 1.month.ago..Time.current })

所有不属于这些条件的结果都不应该显示出来

当想要“组合”多个标准时,最主要的事情是决定“计算”如何计算产生这种效果的权重。斯芬克斯计算一个重量,并以此为基础进行排序。而不是多个不同查询的并集

比如说

将使用“全文”搜索权重,但如果在上个月添加1000

使用sphinx NOW()函数

您可能还需要字段权重 将
标题
匹配提升到“文本”匹配之上

ThinkingSphinx.search(
  :select => '*, WEIGHT() + IF(publish_at>NOW()-2592000,1000,0) AS custom_weight',
  :order  => 'custom_weight DESC'
)
把所有的东西都放在一起(如果ruby语法正确的话…)


。。。理论上,冠军赛将是第一场。最近也有关于start的报道。不完全是你想要的,但很接近

当想要“组合”多个标准时,最主要的事情是决定“计算”如何计算产生这种效果的权重。斯芬克斯计算一个重量,并以此为基础进行排序。而不是多个不同查询的并集

比如说

将使用“全文”搜索权重,但如果在上个月添加1000

使用sphinx NOW()函数

您可能还需要字段权重 将
标题
匹配提升到“文本”匹配之上

ThinkingSphinx.search(
  :select => '*, WEIGHT() + IF(publish_at>NOW()-2592000,1000,0) AS custom_weight',
  :order  => 'custom_weight DESC'
)
把所有的东西都放在一起(如果ruby语法正确的话…)


。。。理论上,冠军赛将是第一场。最近也有关于start的报道。不完全是你想要的,但很接近

看到编辑后,您可能别无选择,只能运行两个查询,然后合并。。。怀疑ts是否有联合功能现在看到编辑后,您可能别无选择,只能运行两个查询,然后合并。。。怀疑ts具有联合特性
:field_weights => { :title=>10 }
NewPost.search( query , 
  :select => '*, weight() + IF(publish_at>NOW()-2592000,1000,0) as custom_weight',
  :order  => 'custom_weight DESC', 
  :field_weights => { :title=>10 }
)