如何使用Solr/Lucene对地图进行序列化/反序列化? [英] How to serialize/deserialize a map with Solr/Lucene?

查看:170
本文介绍了如何使用Solr/Lucene对地图进行序列化/反序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Solr的新手,在尝试对Solr中的Map进行序列化/反序列化时遇到了一个问题.

I am new to solr, and I am facing a problem when I try to serialize/deserialize a Map in Solr.

我在Java应用程序中按如下方式使用Spring Data Solr:

I use Spring Data Solr in my Java application as follow:

@Field("mapped_*")
private Map<String, String> values;

它按照以下步骤拉平并序列化我在Solr中的地图:

It flatten and serializes my map in Solr as follow:

"key1" : "value1"
"key2" : "value2"
...

但是,当我运行搜索时,返回的对象的此字段始终设置为NULL.反序列化不适用于此特定字段,它似乎无法将key1,key2 ...识别为Map的一部分.

However, when I run a search, the returned objects have this field always set as NULL. Deserialization does not work on this particular field, it looks like it does not recognize the key1, key2... as part of the Map.

有人知道如何使脱盐工作吗?我必须实现自定义转换器吗?

Does anyone know how to make the derialization work? Do I have to implement a custom converter?

推荐答案

目前,Spring Data Solr不会自动为地图中包含的值加上给定的@Field#value作为前缀,而只会使用Map#key作为字段名.有一个改进( DATASOLR-202 ).

At this time Spring Data Solr does not automatically prefix values contained in the map with the given @Field#value, but will just use the Map#key as fieldname. There's an improvement (DATASOLR-202) open.

这时在 values 中具有key1key2,..的字段要求字段名称为key*,以便正确地读回值.

At this time having key1, key2,.. in values requires the fieldname to be key* in order to read back values correctly.

@Field("key*")
private Map<String, String> values;

这篇关于如何使用Solr/Lucene对地图进行序列化/反序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆