Sha256: c47aed2c621fa820a477761fb51f266f0c2c4e399c69a6ebeb359c4e5e470676

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

# The goal of this method is to have no dependency on OM, so that NOM or RDF datastreams could use this.

module Solrizer
  # Instructions on how to solrize the field (types and uses)
  class Directive
    attr_accessor :type, :index_as
    def initialize(*args)
      case args
      when Hash
        self.type = args[:type]
        self.index_as = args[:index_as]
      when Array
        self.type = args[0]
        self.index_as = args[1]
      end
    end
  end

  module Common
    def self.included(klass)
      klass.send(:extend, ClassMethods)
    end

    module ClassMethods
      # @param [String] field_name_base the name of the solr field (without the type suffix)
      # @param [Object] value the value to insert into the document
      # @param [Directive] directive instructions on which fields to create
      # @param [Hash] solr_doc the solr_doc to insert into.
      def create_and_insert_terms(field_name_base, value, directive, solr_doc)
        Solrizer.default_field_mapper.solr_names_and_values(field_name_base, value, directive.type, directive.index_as).each do |field_name, field_value|
          unless field_value.join("").strip.empty?
            ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_name, field_value)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solrizer-2.2.0 lib/solrizer/common.rb
solrizer-2.1.0 lib/solrizer/common.rb
solrizer-2.1.0.rc1 lib/solrizer/common.rb