【问题标题】:Conditional "OR" in thinking sphinx search with filtering by date range通过日期范围过滤思考狮身人面像搜索中的条件“或”
【发布时间】:2011-07-19 08:30:47
【问题描述】:

我在按日期范围连接条件 OR 和 filterint 时遇到问题。 类似的东西

#pseudo SQL syntax
(@date_start < params[:date_to_search] < @date_end) && (@every_day==1 || @day_of_week== params[:day])

--

class OfferTime < ActiveRecord::Base
  define_index do
    indexes every_day #boolean
    indexes day_of_week #string eg. Tue, Mon etc

    has date_start #Date NOT datetime
    has date_end #Date
  end
end

要进行有条件的 OR,我使用以下解决方案: Conditional "or" in Thinking Sphinx search

这很好用。

(OfferTime.search "@every_day 1 | @day_of_week Tue", :match_mode => :extended).size 
# => 2
# Correct answer

但我不知道如何将其与该日期范围联系起来

(@date_start < params[:date_to_search] < @date_end)

例子:

(OfferTime.search "@every_day 1 | @day_of_week Tue & @date_start < #{1.year.ago}", :match_mode => :extended).size 
# => 1
# wrong answer! should be 0!

ThinkingSphinx 可以做到这一点吗?

【问题讨论】:

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


    【解决方案1】:

    不确定您所追求的确切逻辑 - 是 every day OR (day of week and date start) 还是 (every day OR day of week) AND date start

    后者是可能的 - 但您需要使用 :with 参数过滤属性 - 它应该是 well-covered in the docs。要获得“不到 1 年前”过滤器,您需要使用一个范围 - 从一年前到今天(或远在未来,如果更合适的话)。

    如果是前者,我不确定这是否可能 - 但如果是,您可能需要研究表达式语法和 Sphinx 的 select 子句。同样,TS 文档中的covered a bit 带有指向相关 Sphinx 部分的链接。

    【讨论】:

    • 我遵循逻辑:(@every_day 1 | @day_of_week #{params[:day]}) AND 日期范围 (@date_start &lt; #{params[:date].to_date} @date_end &gt;#{params[:date].to_date})。不幸的是,扩展查询语法中没有“>”或“
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多