solr - SolrJ 和 LocalDate 和 LocalDateTime
问题描述
SolrJ 将 LocalDate 和 LocalDateTime 序列化,但它们不能作为日期(或日期范围)进行搜索,而是作为字符串进行搜索。如果想要让它可搜索,则必须在使用 SolrJ 之前将其转换为 java.util.Date。
有没有办法为 SolrJ 定义自定义序列化程序或将 LocalDate 和 LocalDateTime 也标记为日期字段(因此可搜索)?
谢谢!
编辑:代码示例
String zkHosts = "localhost:2181";
CloudSolrClient client = new CloudSolrClient.Builder().withZkHost(zkHosts).build();
client.setDefaultCollection("playground");
Person test = Person.builder().id("UID-333").createdTimestamp(LocalDateTime.now()).dateOfBirth(LocalDate.now()).gender("male").build();
client.addBean("person", test, 1000);
client.close();
这是保存在 Solr 中的内容:
{
"id":"UID-333",
"dateOfBirth":["java.time.LocalDate:2018-05-15"],
"dateOfBirth_str":["java.time.LocalDate:2018-05-15"],
"gender":["male"],
"gender_str":["male"],
"timestamp":["java.time.LocalDateTime:2018-05-15T15:00:12.433"],
"timestamp_str":["java.time.LocalDateTime:2018-05-15T15:00:12.433"]
}
当然,实体的相应属性用 注释@Field
。
解决方案
推荐阅读
- c++ - C++ 中 std::map 的运行时复杂度是多少?
- java - 我是否需要 Microsoft Graph Api 的管理员同意?
- vuejs2 - 将默认“/”重定向到特定路径 nuxt / netlify
- composer-php - Hybrid Composer/FTP Drupal 8 工作流程问题
- jquery - Laravel 7.x Uncaught ReferenceError: $ is not defined
- python - Pandas 读取包含 \t 的文件地址的 CSV
- reactjs - 将 Typescript 与 Material-UI useStyles 一起使用时将道具传递给类
- sql-server - 由于常量 varchar 列,架构绑定视图索引创建失败
- authentication - 使用随机字符串作为令牌而不是 JWT 进行身份验证
- email - 如何将 CNAME 记录添加到 Google 域?