Martini Indexing Solr Documents
This guide demonstrates how to add a new document to your custom search index. We'll create a script for indexing movie data, highlighting the key objects and methods utilized in the process. For clarity, the data will be manually entered through service inputs.
Prerequisites
Ensure you've already set up a custom Solr core or collection and understand how to create services in the relevant scripting language.
Access the Scripts
Scripts used in this guide are part of the examples
package available in the Lonti Marketplace, where you can also find additional services showcasing Solr-related functionality.
Preparation
Confirm that your custom Solr core is properly configured and connected to the Martini package in use.
Creating the Model
Creating a model to hold movie data is essential. This model can either be manually crafted or generated from an existing schema, such as the schema.xml
file.
Using the Model Generator
You can use a model-generating service to create a model based on the schema.xml
file:
This script should be located in your project's appropriate directory. Modify it as necessary for your specific schema and setup. The steps in this service include:
- Path Definition: Setting a path to the
schema.xml
file. - Reading Schema Content: Extracting the contents of
schema.xml
. - Model Generation: Using a method to convert the schema into a usable model.
Manual Model Creation
Alternatively, create a model manually, such as a Groovy class in this example:
1 2 3 4 5 6 7 8 9 10 |
|
The @Field
annotations are used to denote fields that will be indexed.
Schema Fields
The schema.xml
typically defines several fields, including id
, movieTitle
, and director
. Fields like id
and _version_
are often auto-generated by Solr.
Indexing the Model's Data
Once your model is ready, create a service that handles the indexing.
Service Implementation
Implement a service for indexing data. Here's an overview of what it should include:
- Exception Handling: Use a
try
-catch
block to manage potential errors. - Indexing Operation: Call a method to index the data from your model.
- Logging: Log any exceptions or important information for debugging.
Upon running this service, you'll input the required data, which will then be indexed.