You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by eh...@apache.org on 2007/05/16 16:06:53 UTC

svn commit: r538603 - in /lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer: hpricot_mapper.rb xpath_mapper.rb

Author: ehatcher
Date: Wed May 16 07:06:53 2007
New Revision: 538603

URL: http://svn.apache.org/viewvc?view=rev&rev=538603
Log:
Adjust mappers with dependencies to conditionally load

Modified:
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb?view=diff&rev=538603&r1=538602&r2=538603
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb Wed May 16 07:06:53 2007
@@ -10,11 +10,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-require 'hpricot'
+begin
+  require 'hpricot'
 
-# For files with the first line containing field names
-class Solr::Importer::HpricotMapper < Solr::Importer::Mapper
-  def field_data(doc, path)
-    doc.search(path.to_s).collect { |e| e.inner_html }
+  class Solr::Importer::HpricotMapper < Solr::Importer::Mapper
+    def field_data(doc, path)
+      doc.search(path.to_s).collect { |e| e.inner_html }
+    end
   end
-end
+rescue LoadError => e # If we can't load hpricot
+  class Solr::Importer::HpricotMapper
+    def initialize(mapping, options={})
+      raise "Hpricot not installed."
+    end
+  end
+end
\ No newline at end of file

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb?view=diff&rev=538603&r1=538602&r2=538603
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb Wed May 16 07:06:53 2007
@@ -10,18 +10,26 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-require 'xml/libxml'
+begin
+  require 'xml/libxml'
 
-# For files with the first line containing field names
-class Solr::Importer::XPathMapper < Solr::Importer::Mapper
-  def field_data(doc, xpath)
-    doc.find(xpath.to_s).collect do |node|
-      case node
-        when XML::Attr
-          node.value
-        when XML::Node
-          node.content
+  # For files with the first line containing field names
+  class Solr::Importer::XPathMapper < Solr::Importer::Mapper
+    def field_data(doc, xpath)
+      doc.find(xpath.to_s).collect do |node|
+        case node
+          when XML::Attr
+            node.value
+          when XML::Node
+            node.content
+        end
       end
+    end
+  end
+rescue LoadError => e # If we can't load libxml
+  class Solr::Importer::XPathMapper
+    def initialize(mapping, options={})
+      raise "libxml not installed"
     end
   end
 end