Posts

Showing posts from March, 2016

Integrating sunspot solr in rails with tomcat7

Image
At a first glance it seems too easy to integrate a gem in rails but when it comes to Tomcat7 and java dependencies it always end up in  tricky part so here it is follow these simple steps to integrate solr with all it's dependencies. first you need to have java environment sudo apt-get -y install openjdk-7-jdk sudo mkdir /usr/java sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default Install tomcat sudo apt - get install tomcat7 sudo apt - get install tomcat7 - admin Then download solr (check for a newer version if you want) sudo wget http : //archive.apache.org/dist/lucene/solr/4.8.1/solr-4.8.1.tgz sudo tar - xvf solr - 4.8 . 1.tgz sudo cp - R solr - 4.8 . 1 / example / / opt / solr Set Solr with Tomcat: sudo cp - R / opt / solr / lib / ext /* /usr/share/tomcat7/lib/ sudo cp /opt/solr/webapps/solr.war /var/lib/tomcat7/webapps/solr.war sudo cp -R /opt/solr /var/lib/tomcat7 sudo chown -R tomcat7:tomcat7 /var/lib/tomcat7/solr service tomcat7 restart  i

Removing blank nodes recursively from nokogiri object

While parsing xml using Nokogiri it contains blank nodes in parent and childre nodes it looks like this #<Nokogiri::XML::Text:0x2d02be8 "\n"> and noblanks removes only blank nodes in parent node which become really hard when  recursively fetching nodes. To remove blank nodes recursively from every children and their children this code will work for you.       module NokoHacks       extend ActiveSupport::Concern       Nokogiri::XML::NodeSet.send :include, NokoHacks       Nokogiri::XML::Text.send :include, NokoHacks       Nokogiri::XML::Element.send :include, NokoHacks       def remove_blank_node         self.children.each do |node|           if node.blank?             node.remove           end           if node.children              node.remove_blank_node           end         end       end      end Now apply it the parsed nokogiri object in this code I have also removed namespaces. xml_obj = Nokogiri::XML(File.open('config/london.xml')).remove_names