Skip to content

Apache Lucene open-source search software

Adjust mappers with dependencies to conditionally load

Erik Hatcher2e0bab1770d6
diff --git a/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb b/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb
index f3fe3e0368d..53a48e4314d 100644
--- a/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb
+++ b/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb
@@ -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
diff --git a/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb b/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb
index 4fad299f33d..772e1c3c1f0 100755
--- a/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb
+++ b/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb
@@ -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