Solr Enterprise Search Meeting OFBiz (Part – 2)

Pranay PandeyPublished: Updated:

In my last post Solr Enterprise Search Meeting OFBiz (Part – 1) we saw how to setup Apache Solr on your local computer for development.
Apache Solrofbiz-transparent-logo

In this post we are going to see how to get it to work with Apache OFBiz.

For demonstration purposes, we are going to use example component from OFBiz. The steps shown here will be the same for any other business application. The setup in this tutorial is very basic and will get you on your way to using it with Apache OFBiz. So let’s see how to do it.

Setup core for Apache OFBiz examples in Apache Solr

1. Use solr-4.7.2/example directory as a reference and setup an instance of the Jetty Servlet container to run Solr for your application. Read solr-4.7.2/example/README.txt for more details. The example directory can be copied and renamed as “examples”. The new directory structure should look like:

Solr Enterprise Search Jetty Container Directory

2. Setup the OFBiz example’s core inside the new setup as shown below, again refer to the example core from Solr to do it.

Ofbiz Example Core Structure in Solr

3. Make an entry for the new core that you want to create in $SOLR_HOME/ofbizus/solr/solr.xml as shown below(ofbizus here is the name of a HWM application, you can name it whatever you would like) here we are going to work on the OFBiz example component and want to define the core for it so we are naming it “examples”:

4. Now we define the schema for the examples documents which will be created and indexed for search. Define the schema as mentioned below for the fields in the document in $SOLR_HOME/ofbizus/solr/examples/conf/schema.xml (Code excerpt you can use given below for creating example documents to be indexed):

At this stage we are done with the Solr part, now we have to make it work with OFBiz.

Apache OFBiz Implementation: Preparing example documents as per the schema defined for indexing in Apache Solr

1. If you do not have the example component available within your OFBiz setup, you can get it through SVN from here:
Drop it into the hot-deploy directory.
2. Define and implement a service which will create the example document and indexes as they are created in Solr per the defined document schema. Add a service definition to $OFBIZ_HOME/hot-deploy/example/servicedef/services.xml

2. Create a new configuration file as $OFBIZ_HOME/hot-deploy/example/config/ and put these configurations:

3. Put the implementation of the service you just defined in the src directory at org.ofbiz.example.ExampleServices as mentioned below. This service implementation will take care of connecting to the Solr server, and supply the field values to SOLR to create/update or delete the document for indexing. We have used the Solrj API to work with Solr, make sure to copy it from $ SOLR_HOME/dist/solr-solrj-4.7.2.jar to $OFBIZ_HOME/hot-deploy/example/lib.

4.  We want this service to add/update/delete the example document(being indexed or already indexed) as any of these operations is performed on the example. To do this, we are using an Entity ECA. Create the EECA file as $ OFBIZ_HOME/hot-deploy/example/entitydef/eecas.xml as shown below:


Testing Solr Enterprise Search with Apache OFBiz at this stage

At this stage to test your work
1. Recompile and start OFBiz project with demo data using command-

2. Now start Solr server using:

3. Direct your browser to the OFBiz Example application and create some new examples, observe the activities on the Solr console log. You will see that it has started creating and indexing these documents.

4. Now, direct your browser to the Solr admin console, it should now show the examples core that you defined similar to the image below. Solr Enterprise Search Admin Console
5. Now you can play with it for sometime and check if the new examples that you created in OFBiz are visible here at Solr side. For this you can continue adding examples in OFBiz and find them here in Solr admin console.

Apache Solr Enterprise Search in Action with Apache OFBiz

After starting the Solr and OFBiz servers, you will create a new example, a document will be created and indexed by Solr for it. Now that Solr Search is working with OFBiz, you can follow these steps to build a UI for it and start using Solr Search.

1. Implement a new screen named “FindExampleSolr” in file $ OFBIZ_HOME/hot-deploy/example/widget/ExampleScreens.xml as:

2. Implement GetExampleSearchFacets.groovy(For facets preparation for Example Type and Status on your search view) included in your screen’s action tag at the mentioned location(component://example/webapp/example/WEB-INF/actions/) in your example component as:

3. Implement SearchExamplesByFilters.groovy(Filter search results based on selection) included in FindExampleSolr screen’s action tag at the mentioned location(component://example/webapp/example/WEB-INF/actions/):

4. Implement the FindExample.ftl included in the FindExampleSolr screen’s left column at location component://example/webapp/example/example/ This will be used to show the search box and facets for Example Type and Status.


5. Now implement ListFilteredExamples.ftl included in your FindExampleSolr screen at location component://example/webapp/example/example/ This file will be used to show the search results:

6. Make the new request and view mapping entry in the example app controller.xml as:


7. Add a new menu item for accessing this screen with title “Solr Search Example” in $ OFBIZ_HOME/hot-deploy/example/widget/example/ExampleMenus.xml under ExampleAppBar as:

8. Now let’s test the Solr search implementation done for OFBiz. Direct your browser to https://localhost:8443/example/control/FindExampleSolr to test it. Make sure the Solr server is running as well. The UI for this implementation should look like:
Solr Enterprise Search In Action with Apache OFBiz

Now you can play with it further and do some experiments and enhancements, or you can start implementing Solr search on Products, Customers or Orders. As you move further along to defining a new core document schema, you will need to have a thorough understanding of the search requirements from a buisness aspect. Review the OFBiz data model carefully prior to making decisions on defining the document Schema, because this is what is indexed and searched.

Learn more from Apache Solr Enterprise Search Platform Space.

Keep Learning…

Pranay Pandey About Pranay Pandey
Pranay Pandey has been in the software industry since 2006. He specializes in Enterprise Software Design and Development. At HotWax he currently leads the effort of architecting quality software products and training resources. He continues to be dedicated to the Apache OFBiz open source project since 2007 and became a committer in 2014. He leads our internal training programs in Apache OFBiz, ERP and new technologies under the roof of HotWax University. He is an Electronics graduate and has a masters degree in Computer Applications from Rajeev Gandhi Technical University, Bhopal (M.P.) India. He loves learning and sharing knowledge. He believes that one of the keys to success in this industry is to "keep learning". His hobbies are reading, writing, walking, running, cycling, cooking and watching science fiction movies.

Leave a Reply

Your email address will not be published. Required fields are marked *