Sunday, September 29, 2013

fun with solr - day1: installation and simple example

I had urge of learning something new.
Per dice.com, there is a high demand of Solr skill. Solr is high performance NoSQL search platform/server built using Lucene Core, with XML/HTTP and JSON/Python/Ruby APIs, hit highlighting, faceted search, caching, replication, and a web admin interface.

Watched Yonik Seeley's presentation and Solr 4. The NoSQL Database on YouTube and was very fascinated by that.
List of sites who is already using is pretty impressive too and I just saw serious potential to our new app conversion.

So I decided to learn Solr as my weekend project!

before you have fun with Solr, you want to make sure java is installed.

to check, you just run: $ java -version
on my macbook, it was already installed
$ java -version
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

but not on my EC2 instance so I installed with apt-get
$ sudo apt-get install openjdk-7-jre-headless

Install & Run Solr with Jetty

What is Jetty: Jetty is a pure Java-based HTTP server and Java Servlet container.
For playing purpose, single Solr instance with small Jetty version that already included in solr package is good enough. So let's get it started.

# download binary and unzeip.
$ curl -O http://apache.mirrors.hoobly.com/lucene/solr/4.4.0/solr-4.4.0.tgz
$ tar -xvf solr-4.4.0.tgz
# clean up
$ rm solr-4.4.0.tgz
$ cd solr-4.4.0/example
$ java -jar start.jar

and point your browser to: http://localhost:8983/solr/
Wow that was easy and Amazing interface!




if you are also setting up on EC2 you want to check following setup so that your server can serve tomcat via public ip
(1) go to Elastic IP to associate your instance
(2) go to Security Group > Inbound and make sure 8983 is open



Add and Retrieve document (example from Yonik's presentation)

naoko-macbook:~ nreeves$ curl http://localhost:8983/solr/update -H 'Content-type:application/json' -d'
 [
 {"id": "book1",
  "title": "American Gods",
  "author": "Nail Gaiman"
 }
 ]
 '
{"responseHeader":{"status":0,"QTime":64}}

naoko-macbook:~ nreeves$ curl http://localhost:8983/solr/get?id=book1
{
  "doc":
  {
    "id":"book1",
    "title":["American Gods"],
    "author":"Nail Gaiman",
    "_version_":1447566597403181056}}

How cool.



No comments:

Post a Comment