Document Identifiers
Every indexed document needs to have an unique identifier. The default one should work in most cases, however you may also define a custom one.
Creating an Identity Provider
public interface IdentityProvider<T>
{
/**
* Provides unique string representation of indexed type identifier that is generated with respect to the model type
* restrictions.
*
* @param indexConfig
* @param model
* @return identifier
*/
String getIdentifier(IndexConfig indexConfig, T model);
}
public class ProductIdentityProvider implements IdentityProvider<ProductModel>
{
@Override
public String getIdentifier(final IndexConfig indexConfig, final ProductModel product)
{
final CatalogVersionModel catalogVersion = product.getCatalogVersion();
final String code = product.getCode();
return catalogVersion.getCatalog().getId() + "/" + catalogVersion.getVersion() + "/" + code;
}
}
<bean id="productIdentityProvider" class="com.example.ProductIdentityProvider"/>
Registering an Identity Provider
A custom identity provider should be configured in the indexed type.
Grouping on a Sharded Environment
Using distributed result grouping in an sharded SolrCloud environment has some caveats. To make it work properly, all the documents in each group should be co-located on the same shard and this can be achieved by indexing using a compositeId router. To use a compositeId router, the document's unique identifier should be prefixed by an attribute's (on which we want to group on) value followed by a character "!" and the unique document id.
ShardAwareProductIdentityProvider, which is the default implementation used for sharded environment, allows grouping basing on the product by creating a compositeId with the prefix, which is a base product id.
