条件“或”考虑按日期范围过滤的狮身人面像搜索

发布于 2024-11-25 11:58:14 字数 1114 浏览 0 评论 0 原文

我在按日期范围连接条件 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 我使用这个解决方案: Thinking Sphinx 搜索中的条件“或”

这非常有效。

(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 来实现这一点?

I have problem with connecting conditional OR with filterint by date range.
Something like that

#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

To make conditional OR I use this solution:
Conditional "or" in Thinking Sphinx search

This works quite well.

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

But I don't know how to connect that with that date range

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

Example:

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

Is it possible to make that with ThinkingSphinx?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吲‖鸣 2024-12-02 11:58:14

不确定您所追求的逻辑 - 是每天或(星期几和日期开始),还是(每天或星期几)和日期开始

后者是可能的 - 但您需要使用 :with 参数来过滤属性 - 它应该是 文档中有详细介绍。要获得“不到一年前”的过滤器,您需要使用一个范围 - 从一年前到今天(或者很远的未来,如果更合适的话)。

如果是前者,我不确定这是否可能 - 但如果是,您可能需要研究表达式语法和 Sphinx 的 select 子句。同样,在 TS 文档中介绍了一些内容,其中包含指向相关的狮身人面像部分。

Not sure exactly the logic you're after - is it every day OR (day of week and date start), or (every day OR day of week) AND date start?

The latter is possible - but you'll want to filter on the attribute using the :with arguments - it should be well-covered in the docs. To get a 'less than 1 year ago' filter, you'll need to use a range - from one year ago to today (or well into the future, if that's more appropriate).

If it's the former, I'm not sure if that's possible - but if it is, you'll likely need to investigate the expression syntax and Sphinx's select clause. Again, covered a bit in the TS docs, with links to the relevant Sphinx sections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文