Thứ Năm, 25 tháng 2, 2016

Setup enviroment - Hacking into SOLR

Introduction

Solr is the popular, blazing-fast, open source enterprise search platform built on Apache Lucene. But the most powerful power of Solr is its customisation. This series will help you familar with solr’s source, write plugins and hack to any part of Solr/Lucene.

Setup ide

Download the source
> wget http://www.us.apache.org/dist/lucene/solr/5.5.0/solr-5.5.0-src.tgz
> tar -xvf solr-5.5.0-src.tgz
Solr use ant as build tools, so if you want to deeply understand following steps and customise solr build process, I recommend you to read some book about ant.
> ant -p
Buildfile: /Users/caomanhdat/workspace/lucene-solr/build.xml

Main targets:
 ...
 idea                          Setup IntelliJ IDEA configuration
 ...
> ant idea
Firstly, we list all ant targets that come will solr, and run ant idea to generate all necessary configuration file for Intellij IDEA. After that, we can easily open solr source as normal Intellij project.
Open Solr project inside Intellij IDEA

Solr project structure

Solr source folders
The most important folders in Solr source is
  • core : solr core code
  • contrib : contains contribution modules, like dataimporthandlervelocity…etc
  • solrj : java client to access solr.
Be notice that, Solr/Lucene is the most well tested project. So when I find some Solr feature that hard to understand, I just have to go to correspond test class and everything will be much clearer.
For example: you can try to run TestJsonRequest.testLocalJsonRequest and place breakpoint SearchHandler.handleRequestBody() to understand search flow of Solr. 
A debug screen along with variables window
I hope that through this post, you can open Solr inside your favourite ide and run some unit test to familar with Solr code. In the next part we will examine structure of a QueryParser and write custom QueryParser after that.