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.
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 |
| Scheduled jobs | executor | Job execution control ( JobExecutor ). Required for job stop support |
| Data store | (connector-specific) | Data record variables provided by each data store |
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.
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
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