Skip to content

Commit

Permalink
Merge pull request #2560 from pulibrary/no_nested_objects
Browse files Browse the repository at this point in the history
Don't index nested objects
  • Loading branch information
hackartisan committed Feb 11, 2019
2 parents c413508 + 05b8a93 commit 9d9c681
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -34,7 +34,7 @@ gem "simple_form"
gem "sprockets", ">= 3.7.2"
gem "title"
gem "uglifier"
gem "valkyrie", "1.5.0"
gem "valkyrie", "1.5.1"
gem "valkyrie-derivatives", git: "https://github.com/samvera-labs/valkyrie-derivatives.git"
gem "webpacker", ">= 4.0.x"

Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -768,7 +768,7 @@ GEM
unf_ext (0.0.7.5)
unicode-display_width (1.3.0)
validatable (1.6.7)
valkyrie (1.5.0)
valkyrie (1.5.1)
active-fedora
active-triples
activemodel
Expand Down Expand Up @@ -905,7 +905,7 @@ DEPENDENCIES
tiny_tds
title
uglifier
valkyrie (= 1.5.0)
valkyrie (= 1.5.1)
valkyrie-derivatives!
valkyrie-sequel!
web-console
Expand Down
4 changes: 2 additions & 2 deletions app/indexers/parent_issue_indexer.rb
Expand Up @@ -10,11 +10,11 @@ def to_solr
return {} unless resource.is_a?(Coin)
return {} unless parents.first

parent_attributes.map { |k, v| ["issue_#{k}_tesim", v] }.to_h
parent_attributes.map { |k, v| ["issue_#{k}_tesim", Array.wrap(v).map(&:to_s)] }.to_h
end

def parent_attributes
parents.first.attributes.dup.delete_if { |k, _| parent_keys_suppress.include?(k) }
parents.first.attributes.dup.delete_if { |k, v| parent_keys_suppress.include?(k) || v.blank? }
end

def parent_keys_suppress
Expand Down
2 changes: 1 addition & 1 deletion app/indexers/sorting_indexer.rb
Expand Up @@ -14,6 +14,6 @@ def to_solr
def sort_title
return resource.sort_title if resource.try(:sort_title)
return resource.title.first.to_s.downcase if resource.try(:title) && resource.title.first
resource.id
resource.id.to_s
end
end
37 changes: 37 additions & 0 deletions spec/indexers/parent_issue_indexer_spec.rb
@@ -0,0 +1,37 @@
# frozen_string_literal: true
require "rails_helper"
require "valkyrie/specs/shared_specs"

RSpec.describe ParentIssueIndexer do
it_behaves_like "a Valkyrie::Persistence::Solr::Indexer"
describe "#to_solr" do
context "when given a not-coin" do
it "returns an empty hash" do
indexer = described_class.new(resource: ScannedResource.new)

expect(indexer.to_solr).to eq({})
end
end
context "when given a resource without parents" do
it "returns an empty hash" do
coin = FactoryBot.create_for_repository(:coin)
indexer = described_class.new(resource: coin)

expect(indexer.to_solr).to eq({})
end
end
context "when given a coin with an issue" do
it "returns issue properties" do
coin = FactoryBot.create_for_repository(:coin)
FactoryBot.create_for_repository(:numismatic_issue, member_ids: coin.id)
indexer = described_class.new(resource: coin)

expect(indexer.to_solr).to eq(
"issue_denomination_tesim" => ["$1"],
"issue_issue_number_tesim" => ["1"],
"issue_rights_statement_tesim" => [RightsStatements.no_known_copyright]
)
end
end
end
end
33 changes: 33 additions & 0 deletions spec/indexers/sorting_indexer_spec.rb
@@ -0,0 +1,33 @@
# frozen_string_literal: true
require "rails_helper"
require "valkyrie/specs/shared_specs"

RSpec.describe SortingIndexer do
it_behaves_like "a Valkyrie::Persistence::Solr::Indexer"
describe "#to_solr" do
context "when given a resource with a sort title" do
it "indexes it" do
resource = instance_double(ScannedResource, sort_title: "Sort")
indexer = described_class.new(resource: resource)

expect(indexer.to_solr).to eq(title_ssort: "Sort")
end
end
context "when given a resource with a title" do
it "indexes the first title downcased" do
resource = instance_double(ScannedResource, title: ["Sort"])
indexer = described_class.new(resource: resource)

expect(indexer.to_solr).to eq(title_ssort: "sort")
end
end
context "when there's no titles" do
it "defaults to the id of the resource" do
resource = instance_double(ScannedResource, id: Valkyrie::ID.new("sort"))
indexer = described_class.new(resource: resource)

expect(indexer.to_solr).to eq(title_ssort: "sort")
end
end
end
end

0 comments on commit 9d9c681

Please sign in to comment.