SolrJ和LocalDate以及LocalDateTime

时间:2018-05-15 08:45:16

标签: solr solrj

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进行注释。

0 个答案:

没有答案
相关问题