java - Lucene StandardQueryParser 错误地解析日期字符串
问题描述
我创建了一个 StandardQueryParser 来解析我的过滤器查询以进行搜索。解析器完美解析数值范围查询,搜索提供预期结果。
但是如果我想查询一个 DateTime 字符串,解析器会返回一个意外的值,除了年份之外的所有内容。示例:date:["2021-06-04T18:00:00Z" TO "2021-06-04T19:00:00Z"] -> date:[2021 TO 2021]
其中第一个是客户端上的查询,第二个是查询解析器解析查询后的查询。
预期的查询将被date:[1622822400 TO 1622826000]
转换为正确的纪元时间戳。
对于 PointsConfigMap 的配置,我使用了以下代码迭代模式并提取数字类型。
private void buildQueryParser(SolrCore core) {
standardQueryParser = new StandardQueryParser(contextFilterQueryAnalyzer);
Map<String, PointsConfig> pointsConfigMap = new HashMap<>();
for(var entry : core.getLatestSchema().getFields().entrySet()) {
var type = entry.getValue().getType();
if (type.isPointField()) {
PointsConfig pointsConfig = extractPointsConfig(type);
if (pointsConfig != null) {
pointsConfigMap.put(entry.getKey(), pointsConfig);
}
}
}
standardQueryParser.setPointsConfigMap(pointsConfigMap);
}
private PointsConfig extractPointsConfig(FieldType type) {
switch (type.getNumberType()) {
case DATE:
case LONG:
return new PointsConfig(new DecimalFormat(), Long.class);
case INTEGER:
return new PointsConfig(new DecimalFormat(), Integer.class);
case FLOAT:
return new PointsConfig(new DecimalFormat(), Float.class);
case DOUBLE:
return new PointsConfig(new DecimalFormat(), Double.class);
}
return null;
}
被contextFilterQueryAnalyzer
初始化为:new TokenizerChain(new KeywordTokenizerFactory(Collections.EMPTY_MAP), null)
如何正确配置 StandardQueryParser 以将 DateTime 字符串解析为时间戳?
解决方案
推荐阅读
- angular - 在 MatDialog 中使用 ngx-color-picker 时出现 StaticInjectorError
- javascript - 使用 React 组件的最佳方式
- android - 使用 SharedPreference 保存后 onResume 上的变量值错误
- asp.net - Kentico 基于声明的身份验证 SAML 2.0
- jenkins - 在哪里可以找到在 Jenkins 中更改工作区路径位置的选项?
- python - 使用 pyInstaller 到闪存驱动器后指定 PyPDF2 的文件路径
- javascript - 将 JavaScript TemplateLiteral 转换为 python 字典
- javascript - HTML5:恢复播放的视频
- c++ - 内联 SSE2 程序集因数据更改而崩溃
- docker - 如何创建正确的 .lando.yml 自定义文件?