Supporting empty queries

Background

This article outlines the steps required to configure Funnelback to accept empty queries that return all the search results.

Process

The classic UI supported empty queries using two different methods, via a collection.cfg setting, ui.null_query_enabled, and also via a query processor option nulqok.

The modern UI requires a query to be set before a query will be passed through to Funnelback’s query processor. This means that the ui.null_query_enabled and nulqok settings have no effect when using the modern UI.

The following hook scripts implement a workaround to enable empty queries to run by injecting a null query into the system query field. Empty queries should be accepted as soon as both scripts are saved.

Step 1. Detect an empty query

Create a hook_pre_process.groovy containing the following code:

// Fix to enable ui.null_query_enabled functionality
if ((transaction.question.query == null) || (transaction.question.query == "")) {
   // query must be set to something or padre isn't called _ is stripped out by padre when processing the query
   transaction.question.query = "_"
   transaction.question.originalQuery = "_"
   // set the system query value to run a null query
   transaction.question.additionalParameters["s"] = ["!showallresults"]
}

Step 2. Fix the queryCleaned data model element

Create a hook_post_process.groovy containing the following code:

// Allow the modern UI to handle an undefined queryCleaned value (will occur for the above code as s params aren't included in queryClean)
if ( transaction.response != null && transaction.response.resultPacket.queryCleaned == null)
{
    transaction.response.resultPacket.queryCleaned ="";
}