I created the following SearchComponent that wraps a deduplicate filter around the current query and added it to last-components. It appears to be working, but is there any way I can improve the performance? Would this be considered and added to the filtercache? Am I even caching correctly?

Thanks for any input/suggestions

...
private Map<String, Filter> filtersByField = new HashMap<String, Filter>();

  @Override
  public void prepare(ResponseBuilder rb) throws IOException {
    SolrParams params = rb.req.getParams();

    if (params.getBool(DuplicateParams.DEDUPLICATE, false)) {
      String field = params.get(DuplicateParams.DUPLICATE_FIELD);

      if (field == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Deduplicate field is required");
      }

      Filter filter = filtersByField.get(field);

      if (filter == null) {
filter = new CachingWrapperFilter(new DuplicateFilter(field, DuplicateFilter.KM_USE_FIRST_OCCURRENCE, DuplicateFilter.PM_FAST_INVALIDATION));
        filtersByField.put(field, filter);
      }

      rb.getFilters().add(new FilteredQuery(rb.getQuery(), filter));
    }
  }
...

Reply via email to