Mapping Solr Converter
MappingSolrConverter allows
you to register custom converters for your SolrDocument and SolrInputDocument as
well as for other types nested within your beans. The Converter is not 100% compartible with DocumentObjectBinder and @Indexed has
to be added with readonly=true to
ignore fields from beeing written to solr.
public class Product {
@Field
private String simpleProperty;
@Field("somePropertyName")
private String namedPropery;
@Field
private List<String> listOfValues;
@Indexed(readonly = true)
@Field("property_*")
private List<String> ignoredFromWriting;
@Field("mappedField_*")
private Map<String, List<String>> mappedFieldValues;
@Dynamic
@Field("dynamicMappedField_*")
private Map<String, String> dynamicMappedFieldValues;
@Field
private GeoLocation location;
}
Taking a look as the above MappingSolrConverter will
do as follows:
| Property | Write Mapping |
|---|---|
|
simpleProperty |
|
|
namedPropery |
|
|
listOfValues |
|
|
ignoredFromWriting |
|
|
mappedFieldValues |
|
|
dynamicMappedFieldValues |
|
|
location |
|
To register a custom converter one must add CustomConversions to SolrTemplate initializing
it with own Converterimplementation.
<bean id="solrConverter" class="org.springframework.data.solr.core.convert.MappingSolrConverter">
<constructor-arg>
<bean class="org.springframework.data.solr.core.mapping.SimpleSolrMappingContext" />
</constructor-arg>
<property name="customConversions" ref="customConversions" />
</bean>
<bean id="customConversions" class="org.springframework.data.solr.core.convert.CustomConversions">
<constructor-arg>
<list>
<bean class="com.acme.MyBeanToSolrInputDocumentConverter" />
</list>
</constructor-arg>
</bean>
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg ref="solrClient" />
<property name="solrConverter" ref="solrConverter" />
</bean>
本文介绍了Spring Data Solr中的MappingSolrConverter组件,该组件允许为SolrDocument和SolrInputDocument注册自定义转换器,并提供了示例代码来说明如何进行配置及使用。
386

被折叠的 条评论
为什么被折叠?



