Skip to content

Extending the Platform with Handlers

MECEAP provides tons of extension points allowing custom code to add or change default behavior.

This can be achieved by implementing specific interfaces and exposing it to the Spring Context with @Component or similar.

DocumentFilterCriteriaHandler

Allows to change a FilterCriteria by defining search settings and options for a given document. Every criteria will be intercepted by this handler and will respect the defined settings.

e.g. Adding a negative boost on "old fashioned" type and defining some aggregations for a Document CoffeeRequest

@Component
public class CoffeeReqSearchParams implements DocumentFilterCriteriaHandler<CoffeeRequest> {

    @Override
    void handlerFilterCriteria(FilterCriteria filterCriteria) {
        SearchParams searchParams = filterCriteria.getSearchParams();

        searchParams.addNegativeBoost("coffeeData.type", "old fashioned");

        searchParams.addAggregation(new SearchAggregation()
                .setFieldName("coffeeData.requester.raw")
                .setAggregationType(SearchAggregation.AggregationType.FacetCount)
                .setAggregationName("coffeeData.requester")
                .setTermsAggregationSize(searchParams.getFacetSize())
                .setClazz(CoffeeRequest.class));

        searchParams.addSuggestFields("coffeeData.requester");
    }
}

You can also add/remove some arbitrary criterion using the filterCriteria.and(..) or filterCriteria.getCriterionList()

IndexSettingHandler

Allows to modify the default Mapping Configuration for FullTextSearch.

e.g. Adding new filter and analyser to the default settings for a Document called Supplier

import br.com.me.ceap.dynamic.extension.search.IndexSettingHandler;
import br.com.me.supplier.document.supplier.Supplier;
// ...


@Named
public class SupplierIndexSettingHandler implements IndexSettingHandler<Supplier> {

    @Override
    public IndexSetting settings(IndexSetting defaultSetting) {
        return defaultSetting
                .addFilter(
                        new FilterSetting("myStemmer_ptBR", "stemmer")
                                .addSetting("language", "brazilian"),
                        new FilterSetting("stop_ptBR", "stop")
                                .addSetting("stopwords", "_brazilian_")
                ).addAnalyzer(
                        new AnalyzerSetting("default", "custom")
                                .addCharFilter("html_strip")
                                .addFilter("lowercase", "asciifolding", "stop_ptBR", "stemmer_ptBR")
                );
    }
}

Note that the code is using defaultSetting and adding new filter and analyser to it. The defaultSeeting could be totally ignored, though. In this case just use a new IndexSetting() instead.