Index primitive attribute and/or collection in Hybris

Hybris Logo

1. Overview

In the last article, we saw how to index a custom attribute to Solr in Hybris using a custom FieldValueProvider.

In this article, I will show your how to index a primitive attribute (String, int, double…) or collection without the need of creating a custom FieldValueProvider.

Fortunately, Hybris comes with a pre-existing FieldValueProvider called SpELValueProvider.java and registered as springELValueProvider in Spring.

The idea behind this provider is to make the indexation of primitive attributes and collections easy.

2. Implementation

2.1. Basic primitive attribute

Assuming you want to index a basic Product attribute of type String.

public class ProductModel extends ItemModel {

	// ...
	
	private String _basicAttribute;
	
	// ...
	
}

In this case, create a SolrIndexedProperty with fieldValueProvider as springELValueProvider and valueProviderParameter as basicAttribute.

INSERT_UPDATE SolrIndexedProperty	; name[unique=true]	;type(code)	;fieldValueProvider		;valueProviderParameter
									; basicAttribute	;string		;springELValueProvider	;basicAttribute

The valueProviderParameter takes a Spring Expression Language (SpEL) as value.

2.2. Localized primitive attribute

Indexing a localized attribute is similar to indexing a basic attribute except for the valueProviderParameter should be like getLocalizedAttribute(#lang) for a Product attribute called localizedAttribute.

INSERT_UPDATE SolrIndexedProperty	; name[unique=true]		;type(code)	;localized	;fieldValueProvider		;valueProviderParameter
									; localizedAttribute	;string		;true		;springELValueProvider	;getLocalizedAttribute(#lang)

2.3. Basic collection attribute

Assuming you want to index a basic Product collection attribute of type Collection<String>.

public class ProductModel {

	//...
	
	Collection<String> _basicCollection;
	
	//...
	
}

In this case, the SolrIndexedProperty should be as follow.

INSERT_UPDATE SolrIndexedProperty	; name[unique=true]		;type(code)	;multiValue	;fieldValueProvider		;valueProviderParameter
									; basicCollection		;string		;true		;springELValueProvider	;basicCollection

 

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x