December 24, 2010

Installing solr with tomcat on ubuntu

This article explains steps to install Solr -Lucene search engine under Tomcat on ubuntu. Also important checks to avoid spending a lot of time in debugging are mentioned where-ever needed.


1) JAVA
    First make sure you have latest java SDK installed.
    Using -  
                     dpkg –get-selections | grep sun-java
This may give you following result if java is already installed
sun-java6-bin install
              sun-java6-jdk         install
              sun-java6-jre          install

If not, Install it using - 
                      apt-get install sun-java6-jdk
Make sure:- java was installed properly. check version of java installed with command - 
 java version Or java showversion
Add below line in your ".bashrc" to set JAVA_HOME variable tomcat needs it.
export JAVA_HOME=/usr/lib/jvm/java-6-sun
  
2) TOMCAT
   Install Tomcat 6 with-
                        apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples
Also install MYSQL java driver with -
            apt-get install libmysql-java
if you need connecting to RDBMS MYSQL.
Once tomcat is installed make sure its installed properly by doing
                        curl http://localhost:8080
In above command use the port number configured for tomcat connector listens for HTML1.1. Check for it in"server.xml" under "/usr/lib/tomcat6/conf"

curl shall fetch html page showing "It works" heading and some instructions.
 
3) SOLR
    If everything is good till now, its time to install Solr.
a) Download solr with-
                 wget -c http://apache.tradebit.com/pub/lucene/solr/1.4.1/apache-solr-1.4.1.zip
uncompress it with - unzip apache-solr-1.4.1.zip

b) Now copy the .war file from solr folder to tomcat webapps folder
                cp ~/apache-solr-1.4.1/dist/apache-solr-1.4.1.war /var/lib/tomcat6/webapps/solr.war

c) Also copy solr files as below-
                cp -R ~/apache-solr-1.4.1/example/solr/ /var/lib/tomcat6/solr/

This shall copy "bin" and "conf" folder and readme.txt to "/var/lib/tomcat6/solr/"

"conf" folder shall have following files -
                                 dataimport.properties -(make sure this file has write permissions for tomcat)
                                 elevate.xml
                                 mapping-ISOLatin1Accent.txt
                                 protwords.txt
                                 schema.xml
                                 scripts.conf
                                 solrconfig.xm
                                 spellings.tx
                                 stopwords.tx
                                 synonyms.tx
                                 xslt (folder
                                 my-data-config.xml (data config XML for your solr instance.you will need to edit 
                                                                    this file so you can import mysql data in to solr)

d) Create the "solr.xml" file under "/var/lib/tomcat6/conf/Catalina/localhost/" with - 
                 vi /etc/tomcat6/Catalina/localhost/solr.xml
Note:- XML file name under "/var/lib/tomcat6/conf/Catalina/localhost/" will be the path to access your solr instance like - http://localhost:8080/solr/
Add below contents in "solr.xml"
<Context docBase="/var/lib/tomcat6/webapps/solr.war" debug="0" privileged="true" allowLinking="true" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="/var/lib/tomcat6/solr" override="true" />
</Context&gt;
in Above set solr home where you copied the Solr files in step (c)

Change directory to "/var/lib/tomcat6/solr/" and create data folder with "mkdir data" 
Make sure the tomcat has write permissions to "data" folder.

This completes solr installation .make sure it works by browing here "http://localhost:8080/solr".
This shall give you html page with meassge "Welcome to Solr" with link to solr admin page.


e) make sure contents in solrconfig.xml in /var/lib/tomcat6/solr/conf is correct and what you want for your solr instance .Check that requestHandler with dataimport handler is defined as here. this is important to import data from mysql.

f) Also make sure that "/var/lib/tomcat6/solr/bin" contains MySQL JAVA connector jar .Else while dataimport it may throw exception that JDBC driver not found.
 


g) If you want another instance of Solrr for development purpose 
        -Copy "solr.xml" to "solrdev.xml"  in "/etc/tomcat6/Catalina/localhost/"
         -Also duplicate "solr" folder to "solrdev" in "/var/lib/tomcat6/".
         -Edit "solrdev.xml" to set solr home to "/var/lib/tomcat6/solrdev".
         -Edit "solrdev.xml" from "/var/lib/tomcat6/solrdev/conf" to use respecive "my-data-config.xml"
This instance can be accessed with "http://localhost:8080/solrdev"

Final step, restart Tomcat and check it here "http://localhost:8080/solr/"
use command "/etc/init.d/tomcat6 restart"




Here after refer to following links to successfully import data from MYSQL
http://wiki.apache.org/solr/DIHQuickStart
http://wiki.apache.org/solr/DataImportHandler
http://wiki.apache.org/solr/SearchHandler
http://wiki.apache.org/solr/SolrRequestHandler

For quick review https://docs.google.com/View?id=ddwrxhb8_86dtz2h9dc&pli=1

December 2, 2010

Upgrading FaceBook Connect to New GRAPH API

This Post is continuation to my previous post <a href="http://pandurangzambare.blogspot.com/2010/03/enable-you-site-with-facebook-connect.html">Enable-you-site-with-facebook-connect for facebook connect</a>. As facebook has recently released New GRAPH API's ,there's need to upgrade to Graph Api's.

Graph API's make it very easy to integrate FaceBook Connect for login, registration  or using FB plugin to your website, as compared to previous Connect Api's.

1) First of all new API' need us to define the name-space like below:-

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

2) Once the name-space is defined Include the JS file - http://connect.facebook.net/en_US/all.js - on page where you need to use FaceBook API.

3) Now we need to initialize the FaceBook JS library as below:-

<div id="fb-root"></div>
FB.init({appId: "APP_ID", status: true, cookie: true, xfbml: true});

This completes the basic requirements for FaceBook Graph API's

Set xfbml to true to use FBML on page of interest.

Using FBML tag as below will enable FaceBook login on your website.

<fb:login-button perms="publish_stream,create_event,rsvp_event,offline_access, publish_checkins,user_birthday,user_events,user_interests,user_likes,user_location, user_relationships,user_relationship_details,user_checkins,friends_checkins,friends_birthday, friends_events,friends_location" v="2" size="xlarge" onlogin="window.reload();">Sign in With Facebook<fb:login-button>

OR

If don't want use FBML initialize FaceBook library as below:-

<div id="fb-root"></div>
FB.init({appId: "APP_ID", status: true, cookie: true, xfbml: false});

and use the following tag to show login button:-


<a onclick="FB.login(function(response) {  if (response.session) { window.realod(); } else { show_error(); }});">Signin with faceBook&lt/a>

Simple three steps to include FaceBook login with New GRAPH API on your website.