mirror of https://github.com/apache/lucene.git
Only use symbols for mapping keys. Strings pass through as static field values
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@525031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dcf9e3ea66
commit
7ab87c4293
|
@ -10,34 +10,34 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# For files with the first line containing field names
|
||||
class Solr::Importer::Mapper
|
||||
def initialize(mapping)
|
||||
@mapping = mapping
|
||||
end
|
||||
|
||||
def field_data(orig_data, field_name)
|
||||
case field_name
|
||||
when Symbol
|
||||
orig_data[field_name]
|
||||
end
|
||||
|
||||
def mapped_field_value(orig_data, field_mapping)
|
||||
case field_mapping
|
||||
when String
|
||||
field_mapping
|
||||
when Proc
|
||||
field_mapping.call(orig_data)
|
||||
when Symbol
|
||||
field_data(orig_data, field_mapping)
|
||||
when Enumerable
|
||||
field_mapping.collect {|orig_field_name| mapped_field_value(orig_data, orig_field_name)}.flatten
|
||||
else
|
||||
field_name
|
||||
raise "Unknown mapping for #{field_mapping}"
|
||||
end
|
||||
end
|
||||
|
||||
def map(orig_data)
|
||||
mapped_data = {}
|
||||
@mapping.each do |solr_name, field_mapping|
|
||||
value = case field_mapping
|
||||
when Proc
|
||||
field_mapping.call(orig_data)
|
||||
when String, Symbol
|
||||
field_data(orig_data, field_mapping)
|
||||
when Enumerable
|
||||
field_mapping.collect {|orig_field_name| field_data(orig_data, orig_field_name)}.flatten
|
||||
else
|
||||
raise "Unknown mapping for #{solr_name}: #{field_mapping}"
|
||||
end
|
||||
value = mapped_field_value(orig_data, field_mapping)
|
||||
mapped_data[solr_name] = value if value
|
||||
end
|
||||
|
||||
|
@ -45,4 +45,6 @@ class Solr::Importer::Mapper
|
|||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue