public class DefaultProductSerializer extends Object implements ProductSerializer
ProductSerializer
that transforms a CAS product into a single Solr document based on the following rules:
o) the core product attributes are used to generate Solr fields starting with "CAS...."
o) the product references are converted to Solr fields starting with "CAS.Reference..." or "CAS.RootReference..."
o) all other metadata fields are converted into Solr fields with the same name and number of values.
Note that the field multiplicity must be consistent with its definition in the Solr schema.xml.
This class generates all Solr documents in XML format.Constructor and Description |
---|
DefaultProductSerializer() |
Modifier and Type | Method and Description |
---|---|
protected void |
addKeyValueToMap(Map<String,List<String>> map,
String key,
String value)
Method to add a (key, value) to a multi-valued map with appropriate checks.
|
QueryResponse |
deserialize(String xml)
Method to parse a full XML response document into a list of Product, References and Metadata objects.
|
protected void |
deserializeMultiValueField(String name,
List<String> values,
org.apache.oodt.cas.metadata.Metadata metadata)
Method that deserializes a multi-valued Solr field into a Metadata element.
|
protected void |
deserializeSingleValueField(String name,
String value,
org.apache.oodt.cas.metadata.Metadata metadata)
Method that deserializes a single-valued Solr field into a Metadata element.
|
protected String |
encodeIndexField(String key,
String value)
Method to encode a Solr field indexing instruction.
|
protected String |
encodeUpdateField(String key,
String value,
boolean replace)
Method to encode a field update instruction for the three possible cases:
add new values to a key (1), replace current values for a key (2), remove all values for a key (3).
|
protected String |
generateInsertDocuments(String productId,
Map<String,List<String>> fields)
Utility method to generate a Solr insert document.
|
protected List<String> |
generateUpdateDocuments(String productId,
Map<String,List<String>> fields,
boolean replace)
Utility method to generate Solr update documents.
|
String |
getMimeType()
Mime type of the documents generated by the specific implementation (XML, JSON etc.)
|
List<String> |
serialize(Product product,
boolean create)
Method to transform a CAS Product into one or more documents to be indexed by Solr.
|
List<String> |
serialize(String productId,
org.apache.oodt.cas.metadata.Metadata metadata,
boolean replace)
Method to transform a CAS Metadata object into one or more Solr "update" documents
(i.e.
|
List<String> |
serialize(String productId,
Reference rootReference,
List<Reference> references,
boolean replace)
Method to transform a CAS Product References object into one or more Solr "update" documents
(i.e.
|
public String getMimeType()
getMimeType
in interface ProductSerializer
public List<String> serialize(Product product, boolean create)
serialize
in interface ProductSerializer
product
- : the product to be indexedpublic List<String> serialize(String productId, Reference rootReference, List<Reference> references, boolean replace)
serialize
in interface ProductSerializer
rootReference
- : the product root reference, may be nullreferences
- : list of product references, may be emptyreplace
- : true to replace the existing references, false to add new references to the existing onespublic QueryResponse deserialize(String xml) throws CatalogException
deserialize
in interface ProductSerializer
xml
- : the Solr XML document to parse (input)CatalogException
public List<String> serialize(String productId, org.apache.oodt.cas.metadata.Metadata metadata, boolean replace)
serialize
in interface ProductSerializer
productId
- : the product unique identifiermetadata
- : the CAS metadata hash tablereplace
- : true to override the existing metadata values, false to add new values to the existing ones.
Existing metadata fields not contained in the hash are left unchanged.
Note: the special value Parameters.NULL is used to indicate that the corresponding key must be removed
(as the Metadata object cannot store null or empty lists).protected void addKeyValueToMap(Map<String,List<String>> map, String key, String value)
map
- key
- value
- protected String generateInsertDocuments(String productId, Map<String,List<String>> fields)
productId
- fields
- protected List<String> generateUpdateDocuments(String productId, Map<String,List<String>> fields, boolean replace)
productId
- fields
- replace
- protected String encodeIndexField(String key, String value)
key
- value
- protected String encodeUpdateField(String key, String value, boolean replace)
key
- value
- replace
- protected void deserializeSingleValueField(String name, String value, org.apache.oodt.cas.metadata.Metadata metadata)
name
- : the Solr field namevalue
- : the Solr field single valuemetadata
- : the metadata containerprotected void deserializeMultiValueField(String name, List<String> values, org.apache.oodt.cas.metadata.Metadata metadata)
name
- : the Solr field namevalues
- : the Solr field multiple valuesmetadata
- : the metadata containerCopyright © 1999-2016 Apache OODT. All Rights Reserved.