Skip to content

Commit

Permalink
Use a null indexer by default for Valkyrie
Browse files Browse the repository at this point in the history
As long as Hyrax applications are using Wings, the index will be the one
provided by ActiveFedora. Using a null index by default allows us to start
"writing" data to the Valkyrie indexer throughout the codebase without the
overhead of running a separate index we'll never read from (see:
`Hyrax::Configuration#query_index_from_valkyrie`).
  • Loading branch information
Tom Johnson committed Dec 26, 2019
1 parent aa0bc7c commit 985fe6b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/services/hyrax/solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ def search_by_id(id, opts = {})
private

##
# @api private
# @private
# Return the valkyrie solr index.
#
# Since this module depends closely on RSolr internals and makes use
# of `#connection`, it will always need to connect to a Solr index. Other
# valkyrie indexers used here would, at minimum, need to provide a
# functioning `rsolr` connection.
def valkyrie_index
Hyrax.index_adapter
Valkyrie::IndexingAdapter.find(:solr_index)
end

##
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/indexing_adapter_initializer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'valkyrie/indexing_adapter'
require 'valkyrie/indexing/solr/indexing_adapter'
require 'valkyrie/indexing/null_indexing_adapter'

Rails.application.config.to_prepare do
Valkyrie::IndexingAdapter.register(
Expand All @@ -9,4 +10,7 @@
),
:solr_index
)
Valkyrie::IndexingAdapter.register(
Valkyrie::Indexing::NullIndexingAdapter.new, :null_index
)
end
4 changes: 2 additions & 2 deletions lib/hyrax/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@ def iiif_metadata_fields
attr_writer :iiif_metadata_fields

##
# @return [#save, #save_all, #delete, #wipe] an indexing adapter
# @return [#save, #save_all, #delete, #wipe!] an indexing adapter
def index_adapter
@index_adapter ||= Valkyrie::IndexingAdapter.find(:solr_index)
@index_adapter ||= Valkyrie::IndexingAdapter.find(:null_index)
end

##
Expand Down
26 changes: 26 additions & 0 deletions lib/valkyrie/indexing/null_indexing_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true
module Valkyrie
module Indexing
# A Valkyrie indexer that does nothing for all index requests. This is
# useful for applications using alternate/legacy (e.g. ActiveFedora)
# indexing strategies that don't want the overhead of running separate
# index requests.
class NullIndexingAdapter
def save(resource:)
:noop
end

def save_all(resources:)
:noop
end

def delete(resource:)
:noop
end

def wipe!
:noop
end
end
end
end
2 changes: 1 addition & 1 deletion spec/support/clean_solr.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.configure do |config|
config.before(:each, clean_index: true) do
client = Hyrax.index_adapter.connection
client = Valkyrie::IndexingAdapter.find(:solr_index).connection
client.delete_by_query("*:*", params: { softCommit: true })
end
end

0 comments on commit 985fe6b

Please sign in to comment.