首页 > 解决方案 > 如何对日期索引执行日期范围查询 - SOLR

问题描述

date在 SOLR索引字段上运行范围查询的正确方法是什么。schema.xml以下是字段定义文件的快照:

<dynamicField name="ds_*"  type="pdate"   indexed="true"  stored="false" multiValued="false" docValues="true"/>

上下文:SOLR 文档包含一个日期元素和值,如"ds_clip_date":"2020-10-14T12:00:00Z". 要求是允许用户从本月/过去 30 天/过去 90 天/今年获取文档。

我尝试从 SOLR 查询仪表板在下面构建 - 但这给了我所有文档而不考虑范围:

http://localhost:8983/solr/testcore/select?facet.field=ds_clip_date&facet.query=facet.range%3Dds_clip_date%26f.ds_clip_date.facet.range.start%3D2020-11-17&facet=on&fl=ds_clip_date&q=*%3A*&rows=200&start=0

我得到以下摘要:

"facet_counts":{
    "facet_queries":{
      "facet.range=ds_clip_date&f.ds_clip_date.facet.range.start=2020-11-17":0},
    "facet_fields":{
      "ds_clip_date":[
        "2020-12-15T12:00:00Z",20,
        "2020-12-16T12:00:00Z",14,
        "2020-09-25T12:00:00Z",1,
        "2020-10-14T12:00:00Z",1,
        "2020-10-20T12:00:00Z",1,
        "2020-10-22T12:00:00Z",1,
        "2020-11-24T12:00:00Z",1,
        "2020-12-17T12:00:00Z",1]},
    "facet_ranges":{},
    "facet_intervals":{},
    "facet_heatmaps":{}}

此外,参考其他一些 QA,尝试构建如下:

http://localhost:8983/solr/testcore/select?facet=true&facet.field=ds_clip_date&facet.range=ds_clip_date&f.ds_clip_date.facet.range.start=2020-12-15T00:00:00Z&f.ds_clip_date.facet.range.end=NOW&f.ds_clip_date.facet.range.gap=%2B1DAY

结果如下:

{
  "response":{"numFound":0,"start":0,"numFoundExact":true,"docs":[]
  },
  "facet_counts":{
    "facet_queries":{},
    "facet_fields":{
      "ds_clip_date":[]},
    "facet_ranges":{
      "ds_clip_date":{
        "counts":[
          "2020-12-15T00:00:00Z",0,
          "2020-12-16T00:00:00Z",0,
          "2020-12-17T00:00:00Z",0],
        "gap":"+1DAY",
        "start":"2020-12-15T00:00:00Z",
        "end":"2020-12-18T00:00:00Z"}},
    "facet_intervals":{},
    "facet_heatmaps":{}}}

但是在上面的摘要中,您可以发现 2020-12-15 有 20 个文档被索引。

我正在运行 SOLR 8.7。

标签: solrlucenedate-rangefaceted-search

解决方案


推荐阅读