想要澄清 hybris for solr 中的 valueProvider
Want a clarification on valueProvider in hybris for solr
想通过一些示例了解 hybris for solr 中 value provider 的确切用法。我在 hybris 中从事一个项目,我必须向 Product 添加新属性并希望在产品列表页面中将其显示为 facate。
假设您拥有产品的动态 属性,它不是原始 ProductModel 的一部分。例如 "Few items left in the store" 在类别页面上为产品签名。在您的产品详细信息页面上,您可以根据您的库存水平和其他属性进行计算,并将其显示给客户。但是,如果您想对类别页面上的每个产品都这样做,将花费很多时间。因此,我们的想法是创建一个 ValueProvider,一旦您启动 SOLR 索引并将其添加为索引(缓存)字段,它将计算此动态 属性。因此,在您的类别页面上,您无需再次计算就可以使用此 属性。
另请查看@Sanchit Khera 的答案了解详细信息。
ValueProvider的用途是将复杂的对象,例如(Brand,Price,Unite,...)转换为Solr可以理解的简单原始数据(string,int,double,...)
例如:
- 供应商要转换的品牌 Brand.name
- 提供商要转换的价格 Price.formattedValue
举个例子,假设您的新属性是单位,例如:
1.首先你必须创建一个 ProductUnitValueProvider
public class ProductUnitValueProvider extends AbstractPropertyFieldValueProvider implements Serializable, FieldValueProvider {
@Override
public Collection<FieldValue> getFieldValues(final IndexConfig indexConfig, final IndexedProperty indexedProperty, final Object model) throws FieldValueProviderException
{
if (model instanceof ProductModel)
{
//Product model
final ProductModel product = (ProductModel) model;
//List of fieldValues to be inflated and returned
final Collection<FieldValue> fieldValues = new ArrayList<FieldValue>();
if (product.getUnit() != null)
{
//Create fieldValue, just to make it simple as possible however i would perfer to use FieldNameProvider.getFieldNames() instead, to retrieve all FieldNames for this indexedProperty
String unitName = product.getUnit().getCode();
fieldValues.add(new FieldValue(indexedProperty.getName(), unitName));
}
//Send FieldValues, to be indexed by Solr
return fieldValues;
}
else
{
throw new FieldValueProviderException("Error message!");
}
}
}
2。注册您的供应商,让 Spring
知道
<bean id="productUnitValueProvider" class="xx.yy.zz.ProductUnitValueProvider" />
3。最后将您的 valueProvider 与 SolrIndexedProperty 相关联,并使用 impex
添加它的 SolrIndexType
$solrIndexedType=xxx
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier)[unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;valueProviderParameter
;$solrIndexedType; unit; string ; ; ; ; ; ; ;productUnitValueProvider;
编辑: 在此处查找更多信息 -> https://www.stackextend.com/hybris/index-a-custom-product-property-with-solr-in-hybris/
想通过一些示例了解 hybris for solr 中 value provider 的确切用法。我在 hybris 中从事一个项目,我必须向 Product 添加新属性并希望在产品列表页面中将其显示为 facate。
假设您拥有产品的动态 属性,它不是原始 ProductModel 的一部分。例如 "Few items left in the store" 在类别页面上为产品签名。在您的产品详细信息页面上,您可以根据您的库存水平和其他属性进行计算,并将其显示给客户。但是,如果您想对类别页面上的每个产品都这样做,将花费很多时间。因此,我们的想法是创建一个 ValueProvider,一旦您启动 SOLR 索引并将其添加为索引(缓存)字段,它将计算此动态 属性。因此,在您的类别页面上,您无需再次计算就可以使用此 属性。 另请查看@Sanchit Khera 的答案了解详细信息。
ValueProvider的用途是将复杂的对象,例如(Brand,Price,Unite,...)转换为Solr可以理解的简单原始数据(string,int,double,...)
例如:
- 供应商要转换的品牌 Brand.name
- 提供商要转换的价格 Price.formattedValue
举个例子,假设您的新属性是单位,例如:
1.首先你必须创建一个 ProductUnitValueProvider
public class ProductUnitValueProvider extends AbstractPropertyFieldValueProvider implements Serializable, FieldValueProvider {
@Override
public Collection<FieldValue> getFieldValues(final IndexConfig indexConfig, final IndexedProperty indexedProperty, final Object model) throws FieldValueProviderException
{
if (model instanceof ProductModel)
{
//Product model
final ProductModel product = (ProductModel) model;
//List of fieldValues to be inflated and returned
final Collection<FieldValue> fieldValues = new ArrayList<FieldValue>();
if (product.getUnit() != null)
{
//Create fieldValue, just to make it simple as possible however i would perfer to use FieldNameProvider.getFieldNames() instead, to retrieve all FieldNames for this indexedProperty
String unitName = product.getUnit().getCode();
fieldValues.add(new FieldValue(indexedProperty.getName(), unitName));
}
//Send FieldValues, to be indexed by Solr
return fieldValues;
}
else
{
throw new FieldValueProviderException("Error message!");
}
}
}
2。注册您的供应商,让 Spring
知道<bean id="productUnitValueProvider" class="xx.yy.zz.ProductUnitValueProvider" />
3。最后将您的 valueProvider 与 SolrIndexedProperty 相关联,并使用 impex
添加它的 SolrIndexType$solrIndexedType=xxx
INSERT_UPDATE SolrIndexedProperty;solrIndexedType(identifier)[unique=true];name[unique=true];type(code);sortableType(code);currency[default=false];localized[default=false];multiValue[default=false];useForSpellchecking[default=false];useForAutocomplete[default=false];fieldValueProvider;valueProviderParameter
;$solrIndexedType; unit; string ; ; ; ; ; ; ;productUnitValueProvider;
编辑: 在此处查找更多信息 -> https://www.stackextend.com/hybris/index-a-custom-product-property-with-solr-in-hybris/