hyrax-v2_graph_indexer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3c228444cb3d0e2d5c4697fa414b161fffd0ece95d8da488d3a87b2e8216e4eb
4
+ data.tar.gz: be4552c5a5c335b1566b21d250379c0834d80673df06b38795b428a91621a58c
5
+ SHA512:
6
+ metadata.gz: 4dec66cb7d6cbc5c042f58c669283ba91c8f756ff8d5eb4fc0eb5d31aa9d880bc8afaf99feafc9c573050d7bb2f0b1cb85f59cbe2b4e34a2a1aa1f63493d3ba5
7
+ data.tar.gz: c8dd13415027c00f77864c057b188658d05996d3f5ed64872f5a7f07336cd8560edd20cccb166de9b18f38ea6581f919cc5ad7cd263e06c8bb269c99a698c5b0
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Specify your gem's dependencies in hyrax-v2_graph_indexer.gemspec.
5
+ gemspec
6
+
7
+ gem "sqlite3"
8
+
9
+ # Start debugger with binding.b [https://github.com/ruby/debug]
10
+ # gem "debug", ">= 1.0.0"
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright 2022 Software Services by Scientist.com
2
+
3
+ Additional copyright may be held by others, as reflected in the commit history.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Hyrax::V2GraphIndexer
2
+
3
+ The `Hyrax::V2GraphIndexer` gem encapsulates a quasi-backport of the graph indexing now in [Hyrax](https://github.com/samvera/hyrax)'s `main` branch as well as the Hyrax `3.x` release.
4
+
5
+ What do we mean by a quasi-backport? Namely it doesn't attempt to make the graphing configurable; instead when you include this gem you then replace the venerable and non-performant [Samvera::NestingIndexer](https://github.com/samvera-labs/samvera-nesting_indexer). You instead favor a the graph feature of SOLR.
6
+
7
+ ## Usage
8
+
9
+ Add this gem to your `2.9.x` Hyrax application's Gemfile.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem "hyrax-v2_graph_indexer"
17
+ ```
18
+
19
+ And then execute:
20
+ ```bash
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+ ```bash
26
+ $ gem install hyrax-v2_graph_indexer
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ ## Discussion
32
+
33
+ This gem does not have much in the way of tests; it has instead been tested against production implementations. The lack of tests is a concession to the return on investment of writing tests for a previous major version of Hyrax which no longer sees updates.
34
+
35
+ This code was added to [Adventist's Hyku code-base](https://github.com/scientist-softserv/adventist-dl/) in the [fddb2863 commit](https://github.com/scientist-softserv/adventist-dl/commit/fddb28638a1f5a823399722ffb74916d0f584225).
36
+
37
+ From that commit message:
38
+
39
+ > Prior to this commit, we had disabled the logic for indexing the parent
40
+ > child relationships of objects. This results in broken behavior
41
+ > regarding nesting collections and works. Were we to enable the
42
+ > "classic" strategy for indexing, we created significant (and known)
43
+ > performance issues.
44
+ >
45
+ > With this commit, we are taking code that was backported to the 3.x
46
+ > branch of Hyrax via [samvera/hyrax#5858][5858] and
47
+ > [samvera/hyrax#5916][5916] and projecting that onto the 2.9.x
48
+ > implementation.
49
+ >
50
+ > This projection means that we are not directly backporting but instead
51
+ > structuring the code such that if you include it, it assumes you using
52
+ > SOLR's native graph indexing. The aforementioned PRs put those changes
53
+ > behind a configuration variable; which is not something that makes sense
54
+ > given this "hack."
55
+ >
56
+ > This PR aims to resolve three issues, which by their nature, are
57
+ > inter-related. The issues are:
58
+ >
59
+ > - [x] Adding works to a collection [#59][59]
60
+ > - [x] Backporting graph indexing [#68][68]
61
+ > - [x] Adding a collection to another collection [#70][70]
62
+ >
63
+ > [59]: #59
64
+ > [68]: #68
65
+ > [70]: #70
66
+ > [5858]: samvera/hyrax#5858
67
+ > [5916]: samvera/hyrax#5916
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [Apache 2](https://opensource.org/licenses/Apache-2.0).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ require_relative "lib/hyrax/v2_graph_indexer/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "hyrax-v2_graph_indexer"
5
+ spec.version = Hyrax::V2GraphIndexer::VERSION
6
+ spec.authors = ["Jeremy Friesen"]
7
+ spec.email = ["jeremy.n.friesen@gmail.com"]
8
+ spec.homepage = "https://github.com/scientist-softserv/hyrax-v2_graph_indexer"
9
+ spec.summary = "A quasi-backport of the Hyrax 3+ Graph Indexing."
10
+ spec.description = "A quasi-backport of the Hyrax 3+ Graph Indexing."
11
+ spec.required_ruby_version = ">= 2.6.0"
12
+
13
+ spec.licenses = ["Apache-2.0"]
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["changelog_uri"] = File.join(spec.homepage, "CHANGELOG.md")
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "hyrax", "~> 2.9"
30
+
31
+ # Instead of requiring all of Rails, let's just require the narrowest aspect of Rails to get this
32
+ # configuration/integration working. Besides, Hyrax will bring Rails into this as well.
33
+ spec.add_dependency "railties"
34
+ end
@@ -0,0 +1,32 @@
1
+ module Hyrax
2
+ module V2GraphIndexer
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ config.to_prepare do
6
+ Hyrax::Collections::NestedCollectionPersistenceService.singleton_class.prepend(
7
+ Hyrax::V2GraphIndexer::NestedCollectionPersistenceServiceDecorator::ClassMethods
8
+ )
9
+
10
+ Hyrax::Forms::Dashboard::NestCollectionForm.prepend(
11
+ Hyrax::V2GraphIndexer::NestCollectionFormDecorator
12
+ )
13
+
14
+ Hyrax::Collections::NestedCollectionQueryService.singleton_class.prepend(
15
+ Hyrax::V2GraphIndexer::NestedCollectionQueryServiceDecorator::ClassMethods
16
+ )
17
+
18
+ Hyrax::WorkBehavior.prepend(
19
+ Hyrax::V2GraphIndexer::CollectionNestingDecorator
20
+ )
21
+
22
+ Hyrax::CollectionBehavior.prepend(
23
+ Hyrax::V2GraphIndexer::CollectionNestingDecorator
24
+ )
25
+
26
+ Hyrax::Dashboard::NestedCollectionsSearchBuilder.prepend(
27
+ Hyrax::V2GraphIndexer::NestedCollectionsSearchBuilderDecorator
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module Hyrax
2
+ module V2GraphIndexer
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hyrax/v2_graph_indexer/version"
4
+ require "hyrax/v2_graph_indexer/railtie"
5
+
6
+ module Hyrax
7
+ # The purpose of this module is to consolidate the decorations necessary to leverage the native
8
+ # SOLR graph searches. That native SOLR graph searches replaces the venerable and non-performant
9
+ # nested indexing.
10
+ #
11
+ # These decorations are inspired from the following pull requests:
12
+ #
13
+ # - https://github.com/samvera/hyrax/pull/5858/
14
+ # - https://github.com/samvera/hyrax/pull/5916/
15
+ #
16
+ # This `lib` file is intended to stand in the place of minting a 2.9.x release (or 2.10.0
17
+ # release). In constructing these changes, I have opted not to backport the configuration.
18
+ # Meaning, if you include this `lib` file, you are stating that you will use the native SOLR graph
19
+ # searches. This simplifies some of the logic; most notably avoiding the conditional include of
20
+ # the `Hyrax::CollectionNesting` based on a configuration. Instead we have a module that shadows
21
+ # the methods introduced in the `Hyrax::CollectionNesting`.
22
+ module V2GraphIndexer
23
+ # @note from https://github.com/samvera/hyrax/pull/5916
24
+ module NestCollectionFormDecorator
25
+ def nesting_within_maximum_depth
26
+ true
27
+ end
28
+ end
29
+
30
+ # @note from https://github.com/samvera/hyrax/pull/5916
31
+ module NestedCollectionQueryServiceDecorator
32
+ module ClassMethods
33
+ def query_solr(collection:, access:, scope:, limit_to_id:, nest_direction:)
34
+ query_builder = Hyrax::Dashboard::NestedCollectionsSearchBuilder.new(
35
+ access: access,
36
+ collection: collection,
37
+ scope: scope,
38
+ nesting_attributes: nil,
39
+ nest_direction: nest_direction
40
+ )
41
+
42
+ query_builder.where(id: limit_to_id.to_s) if limit_to_id
43
+ query = clean_lucene_error(builder: query_builder)
44
+ scope.repository.search(query)
45
+ end
46
+ end
47
+ end
48
+
49
+ # @note from https://github.com/samvera/hyrax/pull/5858/
50
+ #
51
+ # This module is responsible for shadowing the methods of Hyrax::CollectionIndexing; we can't
52
+ # easily replace the inclusion of that module. However we can override it's behavior.
53
+ module CollectionNestingDecorator
54
+ def before_update_nested_collection_relationship_indices
55
+ true
56
+ end
57
+
58
+ def after_update_nested_collection_relationship_indices
59
+ true
60
+ end
61
+
62
+ def update_nested_collection_relationship_indices
63
+ true
64
+ end
65
+
66
+ def update_child_nested_collection_relationship_indices
67
+ true
68
+ end
69
+
70
+ def find_children_of(*)
71
+ true
72
+ end
73
+
74
+ def use_nested_reindexing?
75
+ true
76
+ end
77
+
78
+ def reindex_extent
79
+ true
80
+ end
81
+
82
+ def reindex_extent=(val)
83
+ @reindex_extent = val
84
+ end
85
+
86
+ private
87
+
88
+ def reindex_nested_relationships_for(*)
89
+ true
90
+ end
91
+ end
92
+
93
+ # @note from https://github.com/samvera/hyrax/pull/5858/ with modifications based on v2.9.6 of
94
+ # Hyrax.
95
+ module NestedCollectionsSearchBuilderDecorator
96
+ # rubocop:disable Metrics/LineLength
97
+ def show_only_other_collections_of_the_same_collection_type(solr_parameters)
98
+ solr_parameters[:fq] ||= []
99
+ solr_parameters[:fq] += [
100
+ ActiveFedora::SolrQueryBuilder.construct_query(Collection.collection_type_gid_document_field_name => @collection.collection_type_gid),
101
+ "-{!graph from=id to=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_parent}}id:#{@collection.id}",
102
+ "-{!graph to=id from=member_of_collection_ids_ssim#{' maxDepth=1' if @nest_direction == :as_child}}id:#{@collection.id}"
103
+ ]
104
+ end
105
+ # rubocop:enable Metrics/LineLength
106
+ end
107
+
108
+ module NestedCollectionPersistenceServiceDecorator
109
+ # These overrides are needed because nothing in the 2.9.x implementation was explicitly
110
+ # **saving** the collection membership changes; they were being indexed but not saved. It's
111
+ # possible the indexing service was saving the objects.
112
+ module ClassMethods
113
+ def persist_nested_collection_for(parent:, child:)
114
+ child.member_of_collections.push(parent)
115
+ child.save
116
+ end
117
+
118
+ def remove_nested_relationship_for(parent:, child:)
119
+ child.member_of_collections.delete(parent)
120
+ child.save
121
+ true
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :hyrax_v2_graph_indexer do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hyrax-v2_graph_indexer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Friesen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hyrax
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A quasi-backport of the Hyrax 3+ Graph Indexing.
42
+ email:
43
+ - jeremy.n.friesen@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - hyrax-v2_graph_indexer.gemspec
53
+ - lib/hyrax/v2_graph_indexer.rb
54
+ - lib/hyrax/v2_graph_indexer/railtie.rb
55
+ - lib/hyrax/v2_graph_indexer/version.rb
56
+ - lib/tasks/hyrax/v2_graph_indexer_tasks.rake
57
+ homepage: https://github.com/scientist-softserv/hyrax-v2_graph_indexer
58
+ licenses:
59
+ - Apache-2.0
60
+ metadata:
61
+ homepage_uri: https://github.com/scientist-softserv/hyrax-v2_graph_indexer
62
+ source_code_uri: https://github.com/scientist-softserv/hyrax-v2_graph_indexer
63
+ changelog_uri: https://github.com/scientist-softserv/hyrax-v2_graph_indexer/CHANGELOG.md
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.6.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.1.4
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A quasi-backport of the Hyrax 3+ Graph Indexing.
83
+ test_files: []