Skip to content

Commit

Permalink
all but 2 conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingzumwalt committed Oct 26, 2010
1 parent 44957fa commit 5f67b68
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 48 deletions.
9 changes: 1 addition & 8 deletions config/solr_mappings_af_0.1.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
id: id
default: searchable
searchable:
default: _field
date: _date
string: _field
text: _field
symbol: _field
integer: _field
long: _field
boolean: _field
float: _field
double: _field
displayable: _display
facetable: _facet
sortable: _sort
Expand Down
6 changes: 3 additions & 3 deletions lib/active_fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
require 'active_fedora/solr_service.rb'
require "solrizer"

SOLR_DOCUMENT_ID = Solrizer::FieldNameMapper.mappings["id"] unless defined?(SOLR_DOCUMENT_ID)
ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)

require 'ruby-fedora'
require 'active_fedora/base.rb'
require 'active_fedora/content_model.rb'
Expand All @@ -25,6 +22,9 @@
require 'active_fedora/rels_ext_datastream.rb'
require 'active_fedora/semantic_node.rb'

SOLR_DOCUMENT_ID = ActiveFedora::SolrService.id_field unless defined?(SOLR_DOCUMENT_ID)
ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)

module ActiveFedora #:nodoc:

class << self
Expand Down
6 changes: 3 additions & 3 deletions lib/active_fedora/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def to_xml(xml=Nokogiri::XML::Document.parse("<xml><fields/><content/></xml>"))
# If opts[:model_only] == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls .to_solr for each model an object subscribes to.
def to_solr(solr_doc = Solr::Document.new, opts={})
unless opts[:model_only]
solr_doc << {SOLR_DOCUMENT_ID.to_sym => pid, solr_name(:system_create, :date) => self.create_date, solr_name(:system_modified, :date) => self.modified_date, solr_name(:active_fedora_model, :symbol) => self.class.inspect}
solr_doc << {SOLR_DOCUMENT_ID.to_sym => pid, ActiveFedora::SolrService.solr_name(:system_create, :date) => self.create_date, ActiveFedora::SolrService.solr_name(:system_modified, :date) => self.modified_date, ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol) => self.class.inspect}
end
datastreams.each_value do |ds|
# solr_doc = ds.to_solr(solr_doc) if ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) ||( ds.kind_of?(ActiveFedora::RelsExtDatastream) || ( ds.kind_of?(ActiveFedora::QualifiedDublinCoreDatastream) && !opts[:model_only] )
Expand Down Expand Up @@ -869,8 +869,8 @@ def self.load_instance_from_solr(pid,solr_doc=nil)
raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
end
create_date = solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date)].nil? ? solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date).to_s] : solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date)]
modified_date = solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date)].nil? ? solr_doc[Solrizer::FieldNameMapper.solr_name(:system_modified, :date).to_s] : solr_doc[Solrizer::FieldNameMapper.solr_name(:system_modified, :date)]
create_date = solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date).to_s] : solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date)]
modified_date = solr_doc[ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[ActiveFedora::SolrService.solr_name(:system_modified, :date).to_s] : solr_doc[ActiveFedora::SolrService.solr_name(:system_modified, :date)]
obj = self.new({:pid=>solr_doc[SOLR_DOCUMENT_ID],:create_date=>create_date,:modified_date=>modified_date})
obj.new_object = false
#set by default to load any dependent relationship objects from solr as well
Expand Down
6 changes: 3 additions & 3 deletions lib/active_fedora/metadata_datastream_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def set_blob_for_save # :nodoc:
def to_solr(solr_doc = Solr::Document.new) # :nodoc:
fields.each do |field_key, field_info|
if field_info.has_key?(:values) && !field_info[:values].nil?
field_symbol = solr_name(field_key, field_info[:type])
field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
field_info[:values].each do |val|
solr_doc << Solr::Field.new(field_symbol => val)
end
Expand All @@ -55,14 +55,14 @@ def to_solr(solr_doc = Solr::Document.new) # :nodoc:
# This is utilized by ActiveFedora::Base.load_instance_from_solr to set
# metadata values in this object using the Solr document passed in.
# Any keys in the solr document that map to a metadata field key within a MetadataDatastream object
# are set to the corresponding value. Any others are ignored. Solrizer::FieldNameMapper.solr_name
# are set to the corresponding value. Any others are ignored. ActiveFedora::SolrService.solr_name
# is used to map solr key to field key name.
#
# ====Warning
# Solr must be synchronized with data in Fedora.
def from_solr(solr_doc)
fields.each do |field_key, field_info|
field_symbol = Solrizer::FieldNameMapper.solr_name(field_key, field_info[:type])
field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
value = (solr_doc[field_symbol].nil? ? solr_doc[field_symbol.to_s]: solr_doc[field_symbol])
unless value.nil?
if value.is_a? Array
Expand Down
12 changes: 6 additions & 6 deletions lib/active_fedora/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_instance(pid)
def find(args)
if args == :all
escaped_class_name = self.name.gsub(/(:)/, '\\:')
q = "#{Solrizer::FieldNameMapper.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}"
q = "#{ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}"
elsif args.class == String
escaped_id = args.gsub(/(:)/, '\\:')
q = "#{SOLR_DOCUMENT_ID}:#{escaped_id}"
Expand Down Expand Up @@ -89,7 +89,7 @@ def solr_search(query, args={})
def find_by_solr(query, args={})
if query == :all
escaped_class_name = self.name.gsub(/(:)/, '\\:')
SolrService.instance.conn.query("#{Solrizer::FieldNameMapper.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}", args)
SolrService.instance.conn.query("#{ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}", args)
elsif query.class == String
escaped_id = query.gsub(/(:)/, '\\:')
SolrService.instance.conn.query("#{SOLR_DOCUMENT_ID}:#{escaped_id}", args)
Expand All @@ -114,7 +114,7 @@ def find_by_solr(query, args={})
def find_by_fields_by_solr(query_fields,opts={})
#create solr_args from fields passed in, needs to be comma separated list of form field1=value1,field2=value2,...
escaped_class_name = self.name.gsub(/(:)/, '\\:')
query = "#{Solrizer::FieldNameMapper.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}"
query = "#{ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}"

query_fields.each_pair do |key,value|
unless value.nil?
Expand All @@ -125,7 +125,7 @@ def find_by_fields_by_solr(query_fields,opts={})
if class_fields.has_key?(key) && class_fields[key].has_key?(:type)
type = class_fields[key][:type]
type = :string unless type.kind_of?(Symbol)
solr_key = Solrizer::FieldNameMapper.solr_name(key,type)
solr_key = ActiveFedora::SolrService.solr_name(key,type)
end

escaped_value = value.gsub(/(:)/, '\\:')
Expand All @@ -143,7 +143,7 @@ def find_by_fields_by_solr(query_fields,opts={})

#set default sort to created date ascending
unless query_opts.include?(:sort)
query_opts.merge!({:sort=>[Solrizer::FieldNameMapper.solr_name(:system_create,:date)=>:ascending]})
query_opts.merge!({:sort=>[ActiveFedora::SolrService.solr_name(:system_create,:date)=>:ascending]})
else
#need to convert to solr names for all fields
sort_array =[]
Expand All @@ -169,7 +169,7 @@ def find_by_fields_by_solr(query_fields,opts={})

solr_name = field_name
if class_fields.include?(field_name.to_sym)
solr_name = Solrizer::FieldNameMapper.solr_name(key,class_fields[field_name.to_sym][:type])
solr_name = ActiveFedora::SolrService.solr_name(key,class_fields[field_name.to_sym][:type])
end
sort_array.push({solr_name=>sort_direction})
end
Expand Down
4 changes: 2 additions & 2 deletions lib/active_fedora/nokogiri_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ def solrize_accessor(accessor_name, accessor_info, opts={})

def solrize_node(node, accessor_pointer, solr_doc = Solr::Document.new)
generic_field_name_base = self.class.accessor_generic_name(*accessor_pointer)
generic_field_name = Solrizer::FieldNameMapper.solr_name(generic_field_name_base, :text)
generic_field_name = ActiveFedora::SolrService.solr_name(generic_field_name_base, :text)

solr_doc << Solr::Field.new(generic_field_name => node.text)

if accessor_pointer.length > 1
hierarchical_field_name_base = self.class.accessor_hierarchical_name(*accessor_pointer)
hierarchical_field_name = Solrizer::FieldNameMapper.solr_name(hierarchical_field_name_base, :text)
hierarchical_field_name = ActiveFedora::SolrService.solr_name(hierarchical_field_name_base, :text)
solr_doc << Solr::Field.new(hierarchical_field_name => node.text)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/active_fedora/rels_ext_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ def to_solr(solr_doc = Solr::Document.new)
#
# This is utilized by ActiveFedora::Base.load_instance_from_solr to load
# the relationships hash using the Solr document passed in instead of from the RELS-EXT datastream
# in Fedora. Utilizes Solrizer::FieldNameMapper.solr_name to map solr key to
# in Fedora. Utilizes solr_name method (provided by Solrizer::FieldNameMapper) to map solr key to
# relationship predicate.
#
# ====Warning
# Solr must be synchronized with RELS-EXT data in Fedora.
def from_solr(solr_doc)
#cycle through all possible predicates
PREDICATE_MAPPINGS.keys.each do |predicate|
predicate_symbol = Solrizer::FieldNameMapper.solr_name(predicate, :symbol)
predicate_symbol = ActiveFedora::SolrService.solr_name(predicate, :symbol)
value = (solr_doc[predicate_symbol].nil? ? solr_doc[predicate_symbol.to_s]: solr_doc[predicate_symbol])
unless value.nil?
if value.is_a? Array
Expand Down
21 changes: 4 additions & 17 deletions lib/active_fedora/solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
module ActiveFedora
class SolrService

include Solrizer::FieldNameMapper
include Loggable

load_mappings

attr_reader :conn

Expand All @@ -29,7 +32,7 @@ def self.reify_solr_results(solr_result,opts={})
end
results = []
solr_result.hits.each do |hit|
model_value = hit[Solrizer::FieldNameMapper.solr_name("active_fedora_model", :symbol)].first
model_value = hit[solr_name("active_fedora_model", :symbol)].first
if model_value.include?("::")
classname = eval(model_value)
else
Expand Down Expand Up @@ -58,22 +61,6 @@ def self.escape_uri_for_query(uri)
return uri.gsub(/(:)/, '\\:')
end

def self.mappings
Solrizer::FieldNameMapper.mappings
end
def self.mappings=(mappings)
Solrizer::FieldNameMapper.mappings = mappings
end

def self.logger
@logger ||= defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT)
end

# (re)load solr field name mappings
def self.load_mappings( config_path=nil )
Solrizer::FieldNameMapper.load_mappings(config_path)
end


end #SolrService
class SolrNotInitialized < StandardError;end
Expand Down
7 changes: 3 additions & 4 deletions spec/unit/solr_config_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ class Basic
describe "field name mappings" do
it "should default to using the mappings for the current schema" do
from_default_yml = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings.yml")))
ActiveFedora::SolrService.mappings.should == from_default_yml
ActiveFedora::SolrService.mappings["date"].should == "_dt"
ActiveFedora::SolrService.mappings[:searchable].data_types[:date].opts[:suffix].should == from_default_yml["searchable"]["date"]
end
it "should allow you to provide your own mappings file" do
ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
ActiveFedora::SolrService.mappings["date"].should == "_date"
ActiveFedora::SolrService.mappings["symbol"].should == "_field"
ActiveFedora::SolrService.mappings[:searchable].data_types[:date].opts[:suffix].should == "_date"
ActiveFedora::SolrService.mappings[:searchable].data_types[:symbol].opts[:suffix].should == "_field"
end
end

Expand Down

0 comments on commit 5f67b68

Please sign in to comment.