Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

UDLEDGE - Apache Solr - Java Plugin Development

To develop a middleware / plugin which will process the data before


Objective :
it is saved into the SOLR core.

Tools & Software Required:


 Apache SOLR ( http://lucene.apache.org/solr/)
 Any Editor (Eclipse, Netbeans, Notepad++ etc)
 Windows Operating System(7 onwards) / Linux Operating System
 Java Runtime Environment (JRE) version 1.8 or higher

Solr is the popular, blazing-fast, open source enterprise search platform built on
Apache Lucene.

Solr is highly reliable, scalable and fault tolerant, providing distributed indexing,
replication and load-balanced querying, automated fail-over and recovery,
centralized configuration and more. Solr powers the search and navigation features
of many of the world's largest internet sites.

Basic steps to follow:


1. Download and install Apache Solr from the above given link.
2. Start the Solr Server system.
3. Setup the test core.
4. Setup & configure the plugin.
5. Restart the Solr Server system.
6. Test the Solr core by using Solr Admin panel for the test purpose. Commands
and test cases given below to confirm the testing process.

Starting Solr Server


 Assuming Apache Solr is downloaded and extracted to C drive on your windows
system.
 Go to command prompt and navigate to the bin folder.
 CD C:\solr-7.2.1\bin
 Type the following command at the prompt:
 Solr.cmd start
 By default, Solr will start on port 8983.
 To confirm, it is working properly, open any web browser and type the following
in the address bar:
 localhost:8983

Page 1 of 5
UDLEDGE - Apache Solr - Java Plugin Development

Setup Test Core:


 Now execute the following command at the SOLR command prompt
 Solr.cmd create -c my_test_core -d _default
 The above command will create a new core named “my_test_core” in the Solr
Server.

Define Fields in the core:


 By using the SOLR admin panel, we will not setup the required fields in the core
“my_test_core”.
 Access the SOLR admin panel. Ensure, that “my_test_core” is selected in the
core list, as shown in the above image.
 Click on the schema link in the available list of options provided under the
selected core. This will open an interface, using which we will setup few fields
for our schema.

Page 2 of 5
UDLEDGE - Apache Solr - Java Plugin Development

 Click on “Add Field” button as selected on the previous image.It will show the
following interface:

 Define the following fields using the above interface. For each field, after
specifying the various attributes, click on “Add Field” button to save the field to
the selected schema.

Name Author_name Author_age Author_Country


_Code
Field Type String Plong String
Default 0
Stored(Checkbox) Checked Checked Checked
Indexed(Checkbox) Checked Checked Checked

Basic Solr Operations:

 We will be making use of the Solr Admin panel, to Add, Select & Delete records
to our core “my_test_core”.
 In order to do so, we need to access “Documents” option from the left panel
under the selected core.
 This will option a new interface which we will be making use to perform the
following set of actions:
 Add new documents to the core.
 Delete existing documents from the selected core.

Page 3 of 5
UDLEDGE - Apache Solr - Java Plugin Development

 As depicted above, first click on “Documents” and then select “Solr Command”
under “Document Type” drop-down option.
 Enter the following XML document to create a new document in the core.
<add>
<doc>
<field name="Author_name">Heartine Lazar</field>
<field name="Author_age">42</field>
<field name="Author_Country_Code">IN</field>
</doc>
</add>
 Click on “Submit Document” button. Similarly add one more XML document
entry
<add>
<doc>
<field name="Author_name">ritesh kumar</field>
<field name="Author_age">42</field>
<field name="Author_Country_Code">in</field>
</doc>
</add>

 To view the added documents, click on the “Query” option from the left panel.
 Once the query interface is open, click on the “Execute Query” button to get the
list of documents saved in the core.
 You will be presented with an JSON based output for the stored documents.

Page 4 of 5
UDLEDGE - Apache Solr - Java Plugin Development

Remove Documents from the core:


 In order to remove documents from the selected core, we will be again making
use of “Documents” option from the left panel, with the “Document Type”
having “Solr Command…” selected.
 Enter the following XML option in the interface and click on “Submit Document”.
<delete>
<query>*:*</query>
</delete>
 The above option will empty the selected core and no documents will be
available under the core, when you execute query for the same core.

Middleware/Plugin requirement: (RequestHandlers & Update Pre


Processors)
1. Author name data should have always “Title Case” values when data is saved
into it.
2. Author name data should have only one space between words. Any extra space
should be trimmed out.
3. Author Country Code should always be two characters only.
4. Author Country Code data should be always in “Upper-Case” letters only.
5. Author Age, if entered negative, only the absolute value of the number is to be
saved.

 Setup the java plugin/middleware to take care of the above requirements.


 Generate the needed jar file and package it and configure it for the Solr core.
 Remove the documents from the core.
 Restart the Solr core.
 Add documents to the core and check your results for the compliance.
 Once everything is verified, please email the source files, jar files and
configuration steps to the following email: hlaazar@gmail.com

Contact Information
Name : Heartine Lazaar
Mobile : 011-3708-9492
Email : hlaazar@gmail.com
Company : www.udledge.com

Page 5 of 5

You might also like