forked from cbeer/fcrepo-jms-indexer-solr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace rubydora with (non-thread-safe\!) ActiveFedora/solrizer imple…
…mentation
- Loading branch information
Showing
3 changed files
with
66 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,57 @@ | ||
require 'java' | ||
require 'loggable' | ||
require 'rubydora' | ||
require 'rubygems' | ||
require 'active_fedora' | ||
|
||
java_package 'org.fcrepo.indexer.solr' | ||
|
||
class DemoRubySolrIndexer | ||
include org.fcrepo.indexer.solr.ScriptIndexer | ||
|
||
|
||
class TestConfigurator | ||
attr_reader :fedora_config, :solr_config, :predicate_config | ||
|
||
def init(options = {}) | ||
@fedora_config = options[:fedora_config] | ||
@solr_config = options[:solr_config] | ||
@predicate_config = options[:predicate_config] | ||
end | ||
end | ||
|
||
def indexObject profile, pid, solr_document | ||
|
||
solr_document.addField("__org.fcrepo.indexer.solr.class__", self.class.name); | ||
|
||
repo = Rubydora.connect :url => profile.repository_url | ||
@config_params = { | ||
:fedora_config => { :url => profile.repository_url }, | ||
:solr_config => { :url => profile.repository_url }, | ||
:predicate_config => { | ||
:default_namespace => 'info:fedora/fedora-system:def/relations-external#', | ||
:predicate_mapping => { | ||
'info:fedora/fedora-system:def/relations-external#' => { :has_part => 'hasPart' } | ||
} | ||
} | ||
} | ||
|
||
ActiveFedora.configurator = DemoRubySolrIndexer::TestConfigurator.new | ||
ActiveFedora.init @config_params | ||
|
||
begin | ||
obj = ActiveFedora::Base.find(pid) | ||
rescue ActiveFedora::ObjectNotFoundError | ||
return | ||
end | ||
|
||
obj.to_solr.each do |key, values| | ||
next if key == :id | ||
Array(values).each do |v| | ||
solr_document.add_field(key.to_s, v.to_s) | ||
end | ||
end | ||
|
||
obj = repo.find(pid) | ||
end | ||
|
||
return if obj.new? | ||
|
||
obj.profile.each do |key, values| | ||
Array(values).each do |v| | ||
solr_document.add_field(key, v) | ||
end | ||
end | ||
|
||
|
||
end | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters