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/04/03 06:50:54 UTC
svn commit: r525033 - in /lucene/solr/trunk/client/ruby/solr-ruby:
lib/solr/importer.rb lib/solr/importer/xpath_mapper.rb
test/unit/xpath_mapper_test.rb test/unit/xpath_test_file.xml
Author: ehatcher
Date: Mon Apr 2 21:50:54 2007
New Revision: 525033
URL: http://svn.apache.org/viewvc?view=rev&rev=525033
Log:
Add XPathMapper, useful for mapping XML file data into Solr
Added:
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb (with props)
lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_mapper_test.rb (with props)
lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_test_file.xml
Modified:
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer.rb
Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer.rb?view=diff&rev=525033&r1=525032&r2=525033
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer.rb Mon Apr 2 21:50:54 2007
@@ -13,3 +13,4 @@
module Solr; module Importer; end; end
require 'solr/importer/mapper'
require 'solr/importer/tab_delimited_file_source'
+require 'solr/importer/xpath_mapper'
\ No newline at end of file
Added: 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=auto&rev=525033
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb Mon Apr 2 21:50:54 2007
@@ -0,0 +1,27 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+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
+ end
+ end
+ end
+end
Propchange: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb
------------------------------------------------------------------------------
svn:executable = *
Added: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_mapper_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_mapper_test.rb?view=auto&rev=525033
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_mapper_test.rb (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_mapper_test.rb Mon Apr 2 21:50:54 2007
@@ -0,0 +1,33 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'solr'
+require 'test/unit'
+
+class XPathMapperTest < Test::Unit::TestCase
+
+ def setup
+ @doc = XML::Document.file(File.expand_path(File.dirname(__FILE__)) + "/xpath_test_file.xml")
+ end
+
+ def test_simple_xpath
+ mapping = {:solr_field1 => :'/root/parent/child',
+ :solr_field2 => :'/root/parent/child/@attribute'}
+
+ mapper = Solr::Importer::XPathMapper.new(mapping)
+ mapped_data = mapper.map(@doc)
+
+ assert_equal ['text1', 'text2'], mapped_data[:solr_field1]
+ assert_equal ['attribute1', 'attribute2'], mapped_data[:solr_field2]
+ end
+
+end
Propchange: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_mapper_test.rb
------------------------------------------------------------------------------
svn:executable = *
Added: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_test_file.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_test_file.xml?view=auto&rev=525033
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_test_file.xml (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/test/unit/xpath_test_file.xml Mon Apr 2 21:50:54 2007
@@ -0,0 +1,6 @@
+<root>
+ <parent>
+ <child attribute="attribute1">text1</child>
+ <child attribute="attribute2">text2</child>
+ </parent>
+</root>
\ No newline at end of file