我有:
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 with 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 })
结果需要摘录
更新
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 })
并且所有不属于这些条件的结果都不应显示
答案 0 :(得分:0)
想要结合'多个标准是决定计算'如何计算产生这种效果的重量。狮身人面像计算一个重量和顺序。而不是多个不同查询的联合
例如 https://freelancing-gods.com/thinking-sphinx/searching.html#sorting
ThinkingSphinx.search(
:select => '*, WEIGHT() + IF(publish_at>NOW()-2592000,1000,0) AS custom_weight',
:order => 'custom_weight DESC'
)
会使用'全文'搜索权重,但如果在上个月增加1000。
使用sphinx NOW()函数 http://sphinxsearch.com/docs/current.html#expr-func-now
您可能还需要字段权重
https://freelancing-gods.com/thinking-sphinx/searching.html#fieldweights
通过'文字'提升title
次匹配匹配
:field_weights => { :title=>10 }
带来所有的东西(如果得到ruby语法正确的话......)
NewPost.search( query ,
:select => '*, weight() + IF(publish_at>NOW()-2592000,1000,0) as custom_weight',
:order => 'custom_weight DESC',
:field_weights => { :title=>10 }
)
...理论上冠军头衔将是第一名。最近也开始了。不完全是你要求的,但接近。