How to serialize/deserialize a map with Solr/Lucen

2019-09-06 21:12发布

问题:

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

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

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

It flatten and serializes my map in Solr as follow:

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

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?

回答1:

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.

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;