Using Apache SOLR with Spring Framework
This documentation is about the steps required to use Apache SOLR search engine with Spring framework in Windows OS. I was assigned to use SOLR search engine in my previous project, and I would like to keep that knowledge here. It is intended solely for my self as a reference, if I ever needed to perform such task in the future, then here they are:
#1. Setup Apache SOLR
To setup SOLR, first you need to download the software here the version as the time when I’m writing this is 3.3, then after finished with the download process, extract the .zip file into a folder e.g. “C:\solr” resulting in the following folder structure:

Browse to “C:\solr\apache-solr-3.3.0\example\solr”, this folder should have 3 sub folder and 2 file like this:

Copy the entire content of it into a new folder e.g. “C:\my_solr_app”, this copy serve as a template and later it can be configured if needed by editing the solr.xml file. Then browse to “C:\solr\apache-solr-3.3.0\dist” and copy file “apache-solr-3.3.0.war” into the same folder of “C:\my_solr_app”. Here are the final content of this folder:

I will be using Apache Tomcat as the web server for SOLR, hence browse to Tomcat configuration directory, in my case it’s “C:\apache-tomcat-6.0.32\conf\Catalina\localhost” add new .xml file “my-solr-app.xml” (it can be any name). Here are the content of the .xml file:
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="C:/my_solr_app/apache-solr-3.3.0.war" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="C:/my_solr_app" override="true"/>
</Context>
Start Apache Tomcat and open a browser to the “http://localhost:8080/my-solr-app/”, you may need to change the port number configured for Tomcat web server. If you see the welcome screen, then you’ve just finished Apache SOLR setup.
#2. Spring Framework configuration
Browse to “C:\solr\apache-solr-3.3.0\dist” and copy file “apache-solr-solrj-3.3.0.jar” into the project classpath. You may also need to copy or download the dependency .jar file. Then Create a new bean inside Spring configuration file like this:
<bean id="solrServer" class="org.apache.solr.client.solrj.impl.CommonsHttpSolrServer">
<constructor-arg value="${solr.serverUrl}"/>
<property name="connectionTimeout" value="${solr.connectionTimeout}"/>
<property name="defaultMaxConnectionsPerHost" value="${solr.defaultMaxConnectionsPerHost}"/>
<property name="maxTotalConnections" value="${solr.maxTotalConnections}"/>
</bean>
#3. Using “solrServer” Spring bean in Service layer
Create org.apache.solr.client.solrj.SolrServer object as one of the member variable in the Service, using spring IOC mechanism. Use the following code snipet to interact with SOLR:
Query:
SolrQuery query = new SolrQuery();
query.setQuery(search);
QueryResponse qr = solrServer.query(query);
return qr.getBeans(SearchItem.class);
Post Item:
solrServer.addBean(item);
solrServer.commit();
Delete Item:
solrServer.deleteById(id);
solrServer.commit();
Refer to Solrj documentation here for more detail on how to interact with SOLR.
Writing programatic test
Testing has always been a common process of software development. In general, it usually take place by running the application, then the programmer or tester navigate into the corresponding use case to test it by specifying input and analyzing the output. This routine is easy to perform and developer see the same way that end user sees from the application. However there are some drawbacks to this method which are: it is performed manually, repetitive, limited ability to test non-visible components, and other developer can’t simply verify proper functioning of the application.
Writing programmatic test is about writing another code to test the application code. It seems like more work for developer at first, but actually it can really help in the long run especially for a large scale application. There are two way of programmatic testing: functional testing and unit testing. Functional testing is somewhat similar to manual testing by performing test just into the higher level by omitting knowledge of the internal implementation of specific features. The difference is that functional testing are written into a code not performed manually by hand. In contrast with functional testing, unit testing works in a lower level of code functionality, it required knowledge of an internal components. To make it simple, functional test perform simulation of input and button click of the application, where unit test perform simulation by call of the components function or method.
With programmatic testing developer can minimize the burden of repetitive task from manual testing by using the computer to perform them. Because the testing task is perform by computer it would run by the same sequence of actions, this reduce the error that is potentially generated by human which tends to overlook details. It is also possible to test the internal detail of the components such as the business logic, or software library. Developer can inspect the implementation details such as algorithms efficiency by calculating the time each time the tests is invoke. Finally this method can greatly prevent bugs that might arise in the application.
There are several tools out there that is specifically used to make writing programmatic test even more appealing, one of the most popular tools JUnit is a simple open source Java testing framework written by Kent Beck and Erich Gamma, available to download at www.junit.org. JUnit feature including assertion for testing the expected result and reporting of testing result. Most of the Java IDE right now provide built in JUnit support that make writing programmatic tests is easy and fun.
New year 2010
It is 2010 now, I felt old and lazy because so many events occured during 2009 and yet I’ve not wrote a single post to record them. Starting from being accepted to work in a private software company, new office location, meeting new friends, learn new stuff like Spring framework, Liferay Portal, portlet development, Open Flash Chart with jofc2 and Dynamic Jasper.
There are also terrorist Attack in Kuningan Jakarta at JW Mariot (again) and Ritz Carlton in the form of suicidal bomb… s#*t happens. The terrorist leader from Malaysia Nurdin M Top is finally killed by the POLRI shortly after the bomb, you reap what you sow I think.
At the beginning of January 2009 I am certain to start my own business, and it seems the progress isn’t quite as I’ve expected. I should work hard so this year it will be better.
Sun Developer Day 2008, Jakarta
It has been about eight month since my last post here and time seems to be going faster than I felt before. The reason for this long, empty and non productive blog because there is no special events ever occur to me during those passing months.<– I’m lying here …because the truth is I was too lazy and failed or refused to capture every single important events that occur during the past few months.
Anyway.. at 6 November 2008, there was an interesting event that I attended. It was Sun Developer Day 2008 which was held in Shangri La Hotel Ball Room, Jakarta. I’ve got the infos from my friend email. Check out the links he gave me, fill out the registration form, then suddenly I’m registered and bound to go to this event.
Shangri La Hotel is located in Jakarta Selatan and luckily I live there (South Jakarta.. not Shangri La). The problem is.. it was Thursday and the event start at 8.00 am. At this rate the usual thing on this route is a long traffic jam. I decided to take the Busway as my transportation to avoid this traffic jam. I’m using this transportation last year during 2007 when I was working in Jakarta Pusat. I was hoping this experience helps me calculate the required time and prepare for the trouble that I’m going to face.
At 07.00 in the morning I was going from my house to the nearest busway shelter (Ragunan Shelter). As I expected, there was a long queue of people who also take the busway, mostly are going to work. But this time the queue was quite organized compared in 2007. I’ve managed to make an illustration of the queuing system (see below), I hope this would someday help me create a better queuing algorithm.

The shelter has 2 tickets counter, and 4 types of queue. The dark blue queue is to get the ticket, it has about 25 to 40 meter long. …aaaand after about 15 minutes I’ve manage to get the ticket and start to join the “real” queue to take the bus. The green queue on the left side is for those who want to take a seat in the bus. The light blue on the right side is for those passengers who are in a hurry and willing to stand on their feet in the bus.
I choose the light blue queue on the right side, this final queue is about 50 – 70 meter long, maybe more. The queue on the left (green) is relatively shorter than the right (light blue) but it takes longer than the light blue queue, because the bus takes more capacity for the people who are willing to stand on their feet compared to those who wanted to take a seat. Besides at this hour everyone seems to be in such a hurry, they’re also choose the light blue queue.
I was able to prove this by observing other people who takes the green queue in almost the same time when I join the light blue queue. ……………aaaand after about more than 30 minutes of waiting and standing in queue, I finally get myself inside the bus. For those passengers that I’m observing they are still waaaay back on their queue. The fastest of course is the yellow queue, but unfortunately I’m not an old people nor pregnant woman, and I don’t consider my self as a disable person.
The trip from Ragunan to Dukuh Atas 2 shelter takes about 30 minutes. I take the shelter bridge which connect to Dukuh Atas 1 shelter passing through Jendral Sudirman statue, and Start walking towards to Shangri La Hotel. The distance from Dukuh Atas 1 shelter to the hotel is about 500 meter.
The Ball Room is on the 2nd floor, and when I’m at the registration, I was asked for my business card to register. At the time I don’t have it, and then I saw young peoples holding a print out paper of the email registration confirmation. Suddenly I’m searching for the hotel’s business center. By asking from the hotel employee, I know the business center is on the 3rd floor. After I got there, I’m asking the person in charge if I can used the Internet and printer. He told me that the cost to use the internet is Rp. 55.000 for half an hour. I told him that I just want to print something from my email and ask him to charge only for the printer. What a relief that he is agreed to my request, nice person.
He told me that the price to print for a single paper in color is Rp. 35.000, and then ask me whether I want to print it in color or black & white. Remembering one of my Physics class, the lecturer told me that 1 meter and 10 meter are both nearly equal to nothing compared to 1 kilometer. Then without asking him further question, I told him to print my registration paper in color. Done printing my registration confirmation he writes me a receipt and gave it together with my registration paper.
Back at the registration, I find no difficulties with my printed registration paper. I was managed to get the boarding pass, and without further waiting I walk into the Ball Room and was officially join Sun Developer Day 2008. I miss the opening.. and when I was inside the Ball Room, it’s like an illusion inside an airplane. Maybe it was some kind of genjutsu (Naruto term). When I started to focus on the stage, the speaker talks about Java Now and in the Future: Java SE 6 and 7. Next is a Demo Shootout from each speaker, I remember a nice JavaFX animation demo is done by Chuk Munn Lee.
At coffee break, the MC make an announcement that the airplane is about to transit in Narita airport. The audiences now starting to move outside the airplane Ball Room. The situation outside the Ball Room has changed compared to when I was moving into the Ball Room, It’s like another genjutsu making of Narita airport. Modern Japanese song is played to make the illusion stronger. Some of them I can’t recognize, there’s a song I remember, it was Utada Hikaru’s first love. I love the piano version better tough, because it gives me a better and relaxing mood in contrast with the lyrics…strange huh.
When finished with coffee break, or I rather should say tea break, because I’m taking tea instead of coffee. I was inside the ballroom again, and this time I choose to have the front seat to get a better look on the screen. I don’t quite remember the topics after the coffee break. My guess is about Web Application Development with Grails, and then Netbeans Profiling capabilities. Finally it’s lunch time, I’ve managed to adapt with the situation and break from the illusion, or maybe the genjutsu performer are running out of their chakra.
After having lunch, the next speakers was from Oracle Indonesia, and then from the founder of JUG Indonesia Frans Thamura. He was giving a kind of motivational speech to the audiences. A kind of speech that eventually motivate a lazy person such as my self to start writing blog. Another representative came form Indonesia is SEAMOLEC. The speaker is a bit awkward, well if I was in her shoe.. to speak in front of hundreds of people can be quite a breath taking experience.
This is the first time I join Sun Developer Day, and the truth is I don’t know the peoples who revolve around this community before. Everything went smoothly, and at the second coffee break I took a photo of my self in front of an “airport image”, making it looks like I was really in some kind of an airport. This photograph will be printed on a post card, and I planed to take it after the closing ceremony.
Good thing happen to me in the lucky draw session near the closing. Without a single sign from last night dream, suddenly I won a door prize. There are three phase of the lucky draw, each will be won by three person. I was in the second phase, along with another guy and a girl wearing hijab.
When the closing ceremony is over, I rush into the photo booth to grab my photograph. But unfortunately I was unable to find my photograph. There is another guy who was also had the same situation like me. This guy asked the photographer to print his photo again. I was also ask the same thing, and then a couple of minute later I have my photograph printed, fresh from the printer.. nice.
Finally I was going back home.. following the same route taken in the morning. And there are a lot of stuff that I’m gonna try, from what I’ve been shown here at Jakarta, Sun Developer Day 2008.
Fasting
Today I’m fasting to pay for my debt at Ramadhan last year. I’m unable to fully complete it because of my classic toothaches is on strike again. In the morning I’m accidentally drinks some water tough, but I think its OK to continue fasting, because I’m completely forgot at that time. Another reason that I’m performing this ritual is that my anti social, health consuming, and not so cool smoking habits needs to stop ASAP. I want to start to live healthy for myself and others. Its not hard but its not easy either, I hope at next posting I’m able not to get my self controlled by nicotine anymore.
Hello Weblog world!
Never thought of having a weblog before, but when I accidentally stumble into a wordpress weblog on google, then i decided to give it a try. Now here I am with my first posting.

leave a comment