How to serialize/deserialize a map with Solr/Lucene?

感情迁移 提交于 2019-12-25 02:55:57

问题


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;


来源:https://stackoverflow.com/questions/29307653/how-to-serialize-deserialize-a-map-with-solr-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!