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

In order to create your custom identity provider, you need to first implement the IdentityProvider interface which provides a unique string representation of indexed type identifier that is generated with respect to the model type restrictions:
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);
}
The ProductIdentityProvider class, which resolves a unique identity of a provider, is an example of implementing the interface:
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;
    }
}
You need to remember to create a bean in the spring context for your identity provider:
<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.