Adjust mappers with dependencies to conditionally load

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@538603 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-05-16 14:06:53 +00:00
parent 4514690cf5
commit 2e0bab1770
2 changed files with 31 additions and 16 deletions

View File

@ -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
rescue LoadError => e # If we can't load hpricot
class Solr::Importer::HpricotMapper
def initialize(mapping, options={})
raise "Hpricot not installed."
end
end
end

View File

@ -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