solr搜索时间范围内的时间

发布于 2024-11-11 02:32:46 字数 417 浏览 3 评论 0原文

我知道 Solr 提供了一个日期字段,它可以存储时间实例,然后可以执行范围查询来匹配在特定范围内具有该字段的所有文档。

我的问题与此相反。我需要将多个时间范围与文档关联,然后搜索搜索时间在这些范围之一内的所有文档。

例如,我正在对出口进行索引,并且有 3-4 个范围,在此期间出口处于打开状态。我需要搜索在特定时间实例开放的所有商店。

执行此操作的一种方法是将持续时间的开始时间和结束时间索引为单独的日期字段,并在搜索期间进行比较,例如

(time1_1 > t AND time1_2 < t) OR (time2_1 > t AND time2_2 < t) ) OR (time3_1 > t AND time3_2 < t)

有没有更好/更快/更干净的方法来做到这一点?

I'm aware that Solr provides a date field which can store a time instance and then range queries can be performed to match all documents which have that field within a particular range.

My problem is the inverse of this. I need to associate multiple time ranges with documents and then search for all documents which have the searched time within one of those ranges.

For e.g. I'm indexing outlets and have 3-4 ranges during which the outlet is open. I need to search for all outlets which are open at a particular time instance.

One way of doing this is to index start time and end time of the durations as separate date fields and compare during search like

(time1_1 > t AND time1_2 < t) OR (time2_1 > t AND time2_2 < t) OR (time3_1 > t AND time3_2 < t)

Is there a better/faster/cleaner way to do this?

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

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

发布评论

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

评论(1

吃不饱 2024-11-18 02:32:46

您的示例看起来索引的实体是直销店,并且您将它们的营业时间和营业时间存储在单独的(可能是动态的)字段中。

如果您要求采用不同的方法,则必须考虑重组现有模式,甚至创建使用另一个实体的附加模式。

一开始这可能看起来很不寻常,但如果这个查询对您的应用程序来说是最重要的,那么您应该考虑将新索引的实体设置为您真正想要查询的内容:特定的时间实例。我认为,时间实例要么是一整天,要么是半天或四分之一天。

该模式将包括 ID、一天或半天或任何您选择的开始日期、结束日期等字段,以及指向插座的 id 的多值列表(存储在当前索引中(使用多核设置) ))。

即使您选择四分之一天分别处理早上、下午和晚上的时间,即使预览了几年,数据也不应该爆炸。

这种不同的模式设置允许您:

  • 在导入期间执行最重要的计算,以便在查询时轻松访问,
  • 简单的查询一次返回您想要的内容

您甚至可以通过使用自定义方式来识别范围来放弃日期字段。我正在考虑根据日期和指示是上午还是下午等的字符串创建标识符。这将用作 SOLR 中的唯一 ID。如果您可以从任何查询的“时间实例”创建这样的 ID,那么您最终会得到一个简单的 ID 查找。

例如
2013年3月3日早上几点开门?

/solr/openhours/select?q=id:2013_03_03_am

返回:
出口 ID 数组。

Your example looks like the entities of your index are the outlet stores and you store their opening and closing times in separate (probably dynamic) fields.

If you ask for a different approach you have to consider to restructure the existing schema or to even create an additional one that uses another entity.

It may seem unusual at first, but if this query is the most essential one to your app then you should consider making the entity of your new index to what you acutally want to query: the particular time instance. I take it, time instance is either a whole day, or maybe half or quarter of a day.

The schema would include fields like the ID, the startdate of the day or half day or whatever you choose, the end of it, and a multivalued list of ids that point to the outlets (stored in your current index (use a multi core setup)).

Even if you choose quarter days to handle morning, afternoon and night hours separately, and even with a preview of several years, data should not explode.

This different schema setup allows you to:

  • do the most important computation during import so that it is easily accessible when querying,
  • simple query that returns in one hit what you seek

You could even forgo Date fields by using a custom way to identify the ranges. I am thinking of creating the identifier from the date and a string that indicates whether it is morning or afternoon etc. This would be used as the unique ID in SOLR. If you can create such an ID from any "time instance" that is queried you'd end up with a simple ID lookup.

e.g.
What is open on 2013/03/03 in the morning?

/solr/openhours/select?q=id:2013_03_03_am

returns:
Array of outlet ids.

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