Thursday, April 14, 2016

Endeca Cartridge Handler : How to Add dynamic Record Filter in RecordSpotlightHandler?

The Record Spotlight cartridge handler can promote either specific records or a set of dynamic records based on a navigation state. Behavio... thumbnail 1 summary
The Record Spotlight cartridge handler can promote either specific records or a set of dynamic records based on a navigation state.

Behaviour : -

RecordSpotlightHandler provides functionality to add any static record filter OOTBs and can be setup using recordFilterBuilders properties. What if some dynamic record filters need to be applied to get featured record or recommendation.

Example : Show 10 featured product excluding the current brand selection by the user.

Solution :-

Extend RecordSpotlightHandler that implements dynamic filtering based on previous request or profile.

Find out the code below to extend


import java.util.ArrayList;

import atg.core.util.StringUtils;
import atg.endeca.assembler.navigation.filter.FilterUtils;
import atg.endeca.assembler.navigation.filter.PropertyConstraint;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.ServletUtil;

import com.endeca.infront.assembler.CartridgeHandlerException;
import com.endeca.infront.cartridge.RecordSpotlight;
import com.endeca.infront.cartridge.RecordSpotlightConfig;
import com.endeca.infront.cartridge.RecordSpotlightHandler;
import com.endeca.infront.cartridge.RecordSpotlightSelection;

public class RecommendationHandler extends RecordSpotlightHandler {

 public void preprocess(RecordSpotlightConfig cartridgeConfig) throws CartridgeHandlerException {

    FilterState filterState = cartridgeConfig.getRecordSelection().getFilterState();

    if (filterState != null) {
      // Update the record filter list with RecordFilters generated by the RecordFilterBuilders.
 List<String> filtersList = filterState.getRecordFilters();
  private void getExcludingList(List<String> tobeAddedFilterList) {
DynamoHttpServletRequest dynamoRequest = ServletUtil.getCurrentRequest();
List<String> excludingItems = (List<String>) dynamoRequest.getAttribute("excludingItems");

if (null != excludingItems) {
for (String product : excludingItems) {
tobeAddedFilterList.add(FilterUtils.not(new PropertyConstraint("product.repositoryId", product)));

Find out sample configurable cartridge templates screenshot

Record Spotlight cartridge handlers filters

Click here to see more post related to Endeca Cartridge Handlers

From Author

Was this post resolve the solution you are looking for? what do you think about this solution?
Provide your comments


  1. Hi,

    Thanks for sharing this.

    I am able to successfully filter the records using this logic, but the dimension value count is not reflected correctly. Means, the RefinementMenu section of the assembler response is not filtered based on the above code. How can I correct that ?

    Records are filtered with the given filter. But the dimension values are not in sync with the records in the results.

  2. Hi Sony,

    Thanks for referring this. Spotlight handler navigation state is generally different than refinement menu handler and spotlight is meant for only display products. If you want this to be achieved across all handlers better to change in navigation state builder so that same filter would be passed to all handlers.

    Let me know incase any issues.

    Ajay Agrawal

    1. Thank you Ajay for the quick response.

      You mean, I need to invoke the NavigationState.updateFilterState(FilterState paramFilterState) ?

    2. Hi Sony,

      Extend NavigationStateProcessor class and override process method. here is method signature

      public void process(NavigationState pNavigationState)

      first get all record filters from navigation state object and set it back using code like below :-

      This will pass same record filter across all handlers.

      I hope this helps.


    3. Thank you Ajay. I will try this.


Text Widget