Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on mediashelf-loggable #30

Merged
merged 1 commit into from Jul 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 44 additions & 38 deletions lib/solrizer.rb
@@ -1,4 +1,6 @@
require 'active_support'
require 'active_support/core_ext/module/attribute_accessors'

module Solrizer
extend ActiveSupport::Autoload

Expand All @@ -12,51 +14,55 @@ module Solrizer
autoload :VERSION, 'solrizer/version'
autoload :XML, 'solrizer/xml'

def self.version
Solrizer::VERSION
end
mattr_accessor :logger, instance_writer: false

def self.default_field_mapper
@@default_field_mapper ||= Solrizer::FieldMapper.new
end
class << self
def version
Solrizer::VERSION
end

def self.default_field_mapper=(field_mapper)
@@default_field_mapper = field_mapper
end
def default_field_mapper
@@default_field_mapper ||= Solrizer::FieldMapper.new
end

def default_field_mapper=(field_mapper)
@@default_field_mapper = field_mapper
end

def self.solr_name(*args)
default_field_mapper.solr_name(*args)
end

# @params [Hash] doc the hash to insert the value into
# @params [String] name the name of the field (without the suffix)
# @params [String,Date,Array] value the value (or array of values) to be inserted
# @params [Array,Hash] indexer_args the arguments that find the indexer
# @returns [Hash] doc the document that was provided with the new field inserted
def self.insert_field(doc, name, value, *indexer_args)
# adding defaults indexer
indexer_args = [:stored_searchable] if indexer_args.empty?
default_field_mapper.solr_names_and_values(name, value, indexer_args).each do |k, v|
doc[k] ||= []
if v.is_a? Array
doc[k] += v
else
doc[k] = v
def solr_name(*args)
default_field_mapper.solr_name(*args)
end

# @params [Hash] doc the hash to insert the value into
# @params [String] name the name of the field (without the suffix)
# @params [String,Date,Array] value the value (or array of values) to be inserted
# @params [Array,Hash] indexer_args the arguments that find the indexer
# @returns [Hash] doc the document that was provided with the new field inserted
def insert_field(doc, name, value, *indexer_args)
# adding defaults indexer
indexer_args = [:stored_searchable] if indexer_args.empty?
default_field_mapper.solr_names_and_values(name, value, indexer_args).each do |k, v|
doc[k] ||= []
if v.is_a? Array
doc[k] += v
else
doc[k] = v
end
end
doc
end
doc
end

# @params [Hash] doc the hash to insert the value into
# @params [String] name the name of the field (without the suffix)
# @params [String,Date] value the value to be inserted
# @params [Array,Hash] indexer_args the arguments that find the indexer
# @returns [Hash] doc the document that was provided with the new field (replacing any field with the same name)
def self.set_field(doc, name, value, *indexer_args)
# adding defaults indexer
indexer_args = [:stored_searchable] if indexer_args.empty?
doc.merge! default_field_mapper.solr_names_and_values(name, value, indexer_args)
doc
# @params [Hash] doc the hash to insert the value into
# @params [String] name the name of the field (without the suffix)
# @params [String,Date] value the value to be inserted
# @params [Array,Hash] indexer_args the arguments that find the indexer
# @returns [Hash] doc the document that was provided with the new field (replacing any field with the same name)
def set_field(doc, name, value, *indexer_args)
# adding defaults indexer
indexer_args = [:stored_searchable] if indexer_args.empty?
doc.merge! default_field_mapper.solr_names_and_values(name, value, indexer_args)
doc
end
end
end
5 changes: 1 addition & 4 deletions lib/solrizer/field_mapper.rb
@@ -1,4 +1,3 @@
require "loggable"
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string/inflections'
module Solrizer
Expand Down Expand Up @@ -100,8 +99,6 @@ def suffix(field_type)

class FieldMapper

include Loggable

# ------ Instance methods ------

attr_reader :id_field, :default_index_types
Expand Down Expand Up @@ -228,7 +225,7 @@ def solr_names_and_values(field_name, field_value, index_types)
values = (results[name] ||= [])
values << value unless value.nil? || values.include?(value)
else
logger.warn "Setting #{name} to `#{value}', but it already had `#{results[name]}'" if results[name]
Solrizer.logger.warn "Setting #{name} to `#{value}', but it already had `#{results[name]}'" if results[name] && Solrizer.logger
results[name] = value
end
end
Expand Down
1 change: 0 additions & 1 deletion solrizer.gemspec
Expand Up @@ -14,7 +14,6 @@ Gem::Specification.new do |s|

s.add_dependency "nokogiri"
s.add_dependency "xml-simple"
s.add_dependency "mediashelf-loggable", "~>0.4.7"
s.add_dependency "stomp"
s.add_dependency "daemons"
s.add_dependency "activesupport"
Expand Down