Viewing the padre command run when a search is input via the modern UI

Managed by | Updated .

Background

Funnelback provides a number of ways for a query to be modified between when a user types in a query to when it's submitted to the query processor.

It can sometimes become confusing when a query isn't returning the expected results and being able to see the actual raw command run by padre-sw is desirable.

This article shows how the command can be intercepted and logged by writing a wrapper script for the padre-sw binary.

Process

Step 1. Create a wrapper script

Log in to the Funnelback server and create a perl script containing the following code. Save the file as $SEARCH_HOME/bin/padre-sw-test.pl

#!/usr/bin/perl -w
use strict;
unshift(@ARGV, "padre-sw");
open (LOG, ">>", "/tmp/logi_cli.log");
for my $key (keys(%ENV)) {
    print LOG "export ".$key."='".$ENV{$key}."'\n";
}
print LOG $ARGV[0];
for (my $count = 1; $count < $#ARGV + 1; $count++) {
    my $arg = $ARGV[$count];
    $arg =~ s/\\/\\\\/g;
    $arg =~ s/"/\\"/g;
    print LOG " \"".$arg."\"";
}
close (LOG);
system(@ARGV);

Step 2. Make the script executable

Make the padre-sw-test.pl script executable (and ensure that the file has the correct ownership and group settings - the same as for the padre-sw binary).

Step 3. Change the padre-sw binary

Edit the collection.cfg for the collection that needs testing. Add/edit the following setting:

query_processor=padre-sw-test.pl

Check that queries are still processed correctly by running a search against the collection.

Queries should now be logged to /tmp/log_cli.log and will include messages similar to:

/tmp/log_cli.log
export REQUEST_URI='/s/search.html'
export REMOTE_ADDR='192.168.16.26'
export SEARCH_HOME='/opt/funnelback'
export HTTP_HOST='search-internal'
export QUERY_STRING='collection=all&profile=_default&query=dot'
/opt/funnelback/bin/padre-sw "-rmcf=FTaVMCGf" "-count_dates=d" "-QL=1" "-QL_rank=1" "-qlog_file=/opt/funnelback/data/all/live/log/queries-search-internal.log"

Don't forget to revert the collection.cfg change once you've finished testing by removing the query_processor=padre-sw-test.pl line from the collection.cfg.

Was this artcle helpful?

Comments