Overview
Groovy is the default scripting language for Fess. It runs on the Java Virtual Machine (JVM) and, while maintaining high compatibility with Java, allows you to write scripts with a more concise syntax.
Basic Syntax
Variable Declaration
String Operations
Collection Operations
Conditional Branching
Loop Processing
Data Store Scripts
Examples of scripts for data store configuration.
Note
In data store scripts, each field=expression line is evaluated independently as a single expression. Therefore, import statements, multi-line def variable declarations, and multi-line control structures that set several fields at once (such as if blocks) cannot be used. When using Java classes, write them as a single expression with a fully qualified class name (FQCN), and use a per-field ternary operator for conditional values (for example, url=data.published ? data.url : null ). Also, the variable name data used here is only an example; the actual variable name depends on the data store connector you use. See Data Store Crawling for details.
Basic Mapping
URL Generation
Content Processing
Date Processing
Available Objects
The objects available in scripts vary depending on the execution context.
| Context | Object | Description |
|---|---|---|
| All contexts | container | DI container. Used to access components via container.getComponent("...") |
| Scheduled jobs | executor | Job execution control ( JobExecutor ). Required for job stop support |
| Data store | (connector-specific) | Data record variables provided by each data store. The variable name depends on the connector |
| Path mapping | url , matcher | The URL string to convert and the regular-expression match result ( Matcher ). Available in replacement settings with the groovy: prefix |
| Document boost | (document fields) | Each field of the target document is available as a variable (used in condition and boost-value expressions) |
Scheduled Job Scripts
Examples of Groovy scripts used in scheduled jobs. In scheduled jobs, container and executor are available. Passing executor to the job’s execute() method enables job stop control.
Note
A scheduled job script is evaluated as a single, complete Groovy script. Therefore, unlike data store scripts, you can use import statements, multi-line def declarations, and multi-line control structures. The “Using Java Classes”, “Accessing Fess Components”, “Error Handling”, and “Debugging and Log Output” examples below also assume this complete-script context.
Execute Crawl Job
Conditional Crawling
Execute Multiple Jobs Sequentially
Using Java Classes
Within Groovy scripts, you can use Java standard libraries and Fess classes.
Date and Time
File Operations
HTTP Communication
Warning
Access to external resources affects performance, so keep it to a minimum.
Accessing Fess Components
You can access Fess components using container.
System Helper
Getting Configuration Values
Executing Searches
Error Handling
import statements must be placed at the top of the script (they cannot be placed inside blocks such as try-catch ). You can catch exceptions with try-catch to control job errors.
Debugging and Log Output
Log Output
Debug Output
Best Practices
Keep it simple: Avoid complex logic and write readable code
Null checks: Utilize
?.and?:operatorsException handling: Handle unexpected errors with appropriate try-catch
Log output: Output logs for easier debugging
Performance: Minimize external resource access
Reference Information
Scripting Overview - Scripting Overview
Data Store Crawling - Data Store Configuration Guide
Scheduler - Scheduler Configuration Guide