0

我正在尝试查找到期日期是否介于今天和指定的另一个日期之间。虽然我的数据库有结果,但搜索查询似乎没有获取值。请帮忙!

这是正在运行的查询: jpaQuery: FullTextQueryImpl(+membershipStatus:full_member +accountManager.firstName:nikki +expiryDate:[20190416 TO 20190516})

此外,数据库的到期日期为 YYYY-MM-dd HH:mm:ss 格式,不确定如何匹配这些字段。

这是查询:

Query expiringInQuery = queryBuilder
    .range()
    .onField("expiryDate")
    .ignoreFieldBridge()
    .from(DateTools.dateToString(today, DateTools.Resolution.DAY)) 
    .to(DateTools.dateToString(expiringDate, DateTools.Resolution.DAY))
    .excludeLimit()
    .createQuery();

这是在实体上:

@Field
@Column(name = "expiryDate")
@Temporal(TemporalType.TIMESTAMP)
@JsonIgnore
@IndexedEmbedded
@DateBridge(resolution=org.hibernate.search.annotations.Resolution.DAY, encoding = EncodingType.STRING)
private Date expiryDate;
4

2 回答 2

0

这就是最终奏效的方法。

 String expiringIn = (inputsMap.get("expiringIn").equals("None")) ? "*" : 
 (inputsMap.get("expiringIn"));
 Date today = DateUtils.truncate(new Date(), Calendar.DATE);

 Query luceneQuery = queryBuilder
            .range()
            .onField("expiryDate")
            .from(today)
            .to(expiringDate)
            .createQuery();

在实体上,

@Field
@Column(name = "expiryDate")
@Temporal(TemporalType.TIMESTAMP)
@JsonIgnore
@IndexedEmbedded
@DateBridge(resolution = org.hibernate.search.annotations.Resolution.MILLISECOND, 
encoding = EncodingType.STRING)
private Date expiryDate;
于 2019-04-17T14:30:12.100 回答
0

如果您将它们存储在日期字段中,请查看此处:https ://lucene.apache.org/solr/guide/6_6/working-with-dates.html

因此正确的语法类似于(你可能会忽略时间)

datefield:[2019-04-16T00:00:00.000Z TO 2019-05-16T23:59:59.999Z]

例如 DateRangeField 也允许像这样的查询

[2014 TO 2014-12-01]

查看链接。

于 2019-04-16T14:34:06.630 回答