Transform search queries and responses when looking up a search index

Every search request received by Funnelback passes through a request pipeline, known as the search lifecycle, that consists of a number of steps. The search request and response processing are handled by corresponding Java request and response servlets.

Modifications to both the request and response can be made at each of the search lifecycle steps, before the request object is initialized, before the response object is initialized and after Funnelback has finished processing the response.

There are two types of plugins that can be used to transform search queries and responses at query time:

Search lifecycle plugins

Implement custom code that manipulates the search data model at various stages of the search lifecycle, when a search is run. Search lifecycle plugins are appropriate for the vast majority of use cases.

Search lifecycle plugins replace search lifecycle hook scripts as used in Funnelback 15.24 and earlier.
Servlet filter plugins

Implement custom code that manipulates the request and response objects before and after the search lifecycle has run.

Servlet filter plugins replace Groovy servlet filter hook scripts as used in Funnelback 15.24 and earlier.

Before you start

Ensure you have a clear understanding of the search lifecycle and search data model, and when the different parts of the data model are initialized in the search lifecycle.


Search lifecycle plugin interface methods

Search lifecycle plugins allow you to manipulate the search data model

The search lifecycle interface allows a plugin to execute code that performs query-time modifications to the question and response data model. This is equivalent to the modifications made by hook scripts in previous versions of Funnelback.

To interact with the search lifecycle, you will need to implement the SearchLifeCyclePlugin interface.

The SearchLifeCyclePlugin provides four different methods:

  • void preProcess(SearchTransaction transaction)

  • void preDatafetch(SearchTransaction transaction)

  • void postDatafetch(SearchTransaction transaction)

  • void postProcess(SearchTransaction transaction)

Each of these should manipulate the SearchTransaction object which contains both the query data under question and results data under response.

A search lifecycle plugin can implement one or more of these methods, so it is possible to write a search lifecycle plugin that modifies the query and also the response.

Servlet filter plugin interface methods

The servlet filter plugins allows a plugin to execute code that performs query-time modifications to the request and response servlets.

To implement a custom servlet filter hook, you will need to implement the SearchServletFilterHook interface.

The SearchServletFilterHook provides three methods:

  • ServletRequest preFilterRequest(SearchServletFilterHookContext context, ServletRequest request)

  • ServletResponse preFilterResponse(SearchServletFilterHookContext context, ServletRequest request, ServletResponse response)

  • void postFilterResponse(SearchServletFilterHookContext context, ServletRequest request, ServletResponse response)

The methods provided by this interface, preFilterRequest, preFilterResponse and postFilterResponse, allow the hook class to intercept and alter the ServletRequest and ServletResponse objects as necessary. There is also access to the profile configuration for the request, via SearchServletFilterHookContext#getCurrentProfileConfig()

Access to the Funnelback search transaction object model is not available from within this hook class, and all requests to Funnelback’s search interface will be processed through these methods, so the performance impact of any servlet plugins must be considered during development.