Debug groovy filter

Managed by | Updated .

Funnelback Logging

See

Test on Single URL

The following groovy skeleton shows how to run the groovy filter over a single URL (for debugging and testing changes).

You should make sure all your debugging is removed/disabled before finalising your script.

exampleFilter.groovy
package customFilters.FILTERNAME;

@groovy.transform.InheritConstructors
public class FILTERNAME
    extends com.funnelback.common.filter.ScriptFilterProvider {
    // *** Create a logger object - replace FILTERNAME with the filter name used in the class definition above
    private static final Logger logger = Logger.getLogger(FILTERNAME.class);
    // We filter all documents
    public Boolean isDocumentFilterable(String documentType) {
        return true;
    }
    // Main filter method
    public String filter(String input, String documentType) {
        // Perform modifications to the input data by modifying the input variable.
        // ...
 
        // *** Print log message to modernui.log
        logger.info("My debug message")
        // *** Print log message to stdout (if using the command line testing method below)
        print "My debug message"
 
        // return the modified version of the input text
        return input;
    }
/* COMMAND TO RUN THIS STANDALONE FOR TESTING:
 $SEARCH_HOME/tools/groovy-1.8.6/bin/groovy -cp "$SEARCH_HOME/lib/java/all/*" <PATH TO GROOVY FILE>
*/
   public static void main(String[] args) {
        def data = new URL("http://url-of-document-to-test").getText();
        // replace FILTERNAME with the correct filter name, COLLECTIONNAME with the correct collection name
        def f = new FILTERNAME("COLLECTIONNAME", false);
        f.filter(data, "html");
  }
}

Everything within the main() function will be run when calling script via command line. 

However when the script is called by Funnelback it will call filter() directly and bypass main() function.

Run the groovy script from the command line, against a specified URL using the following:

Terminal - Run groovy filter for testing.
$SEARCH_HOME/tools/groovy-1.8.6/bin/groovy -cp "$SEARCH_HOME/lib/java/all/*" <PATH TO GROOVY FILE>
Info

cp "/opt/funnelback/lib/java/all/*" Needs to be within quotes because it doesn't understand wildcard '*' and it gets expanded by the shell as a list of JAR file which `-cp` doesn't understand

Was this artcle helpful?

Comments