Skip to content

Commit

Permalink
Merge pull request #964 from dchandekstark/issue-961
Browse files Browse the repository at this point in the history
Adds config setting index_tsim_only_threshold
  • Loading branch information
tpendragon authored Sep 9, 2024
2 parents 0836033 + c844b8d commit a6c33c4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/valkyrie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def storage_adapter
Valkyrie::StorageAdapter.find(self[:storage_adapter].to_sym)
end

def index_tsim_only_threshold
self[:index_tsim_only_threshold].to_i
end

# @api public
#
# The returned anonymous method (e.g. responds to #call) has a signature of
Expand All @@ -118,7 +122,8 @@ def resource_class_resolver

def defaults
{
resource_class_resolver: method(:default_resource_class_resolver)
resource_class_resolver: method(:default_resource_class_resolver),
index_tsim_only_threshold: 1000
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/valkyrie/persistence/solr/model_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def result
# @see https://github.com/samvera-labs/valkyrie/blob/main/solr/config/schema.xml
# @return [Array<Symbol>]
def fields
if value.value.length > 1000
if value.value.length > Valkyrie.config.index_tsim_only_threshold
[:tsim]
else
[:tsim, :ssim, :tesim, :tsi, :ssi, :tesi]
Expand Down
55 changes: 55 additions & 0 deletions spec/valkyrie/persistence/solr/model_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,59 @@ class Resource < Valkyrie::Resource
end
end
end

describe "with a long string value" do
let(:creator) { ("Creator " * 1000).strip }
let(:resource) do
instance_double(Resource,
id: "1",
internal_resource: 'Resource',
title: ["Test", RDF::Literal.new("French", language: :fr)],
author: ["Author"],
creator: creator,
attributes:
{
created_at: created_at,
internal_resource: 'Resource',
title: ["Test", RDF::Literal.new("French", language: :fr)],
author: ["Author"],
creator: creator
})
end

before do
Timecop.freeze
end
after do
Timecop.return
end

it "only maps the long value to the _tsim Solr field" do
expect(mapper.convert!).to eq(
id: resource.id.to_s,
join_id_ssi: "id-#{resource.id}",
title_ssim: ["Test", "French"],
title_tesim: ["Test", "French"],
title_tsim: ["Test", "French"],
title_lang_ssim: ["eng", "fr"],
title_lang_tesim: ["eng", "fr"],
title_lang_tsim: ["eng", "fr"],
title_type_tsim: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"],
title_type_ssim: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"],
title_type_tesim: ["http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"],
author_ssim: ["Author"],
author_tesim: ["Author"],
author_tsim: ["Author"],
author_ssi: ["Author"],
author_tesi: ["Author"],
author_tsi: ["Author"],
created_at_dtsi: created_at.iso8601,
updated_at_dtsi: Time.current.utc.iso8601(6),
internal_resource_ssim: ["Resource"],
internal_resource_tesim: ["Resource"],
internal_resource_tsim: ["Resource"],
creator_tsim: [creator]
)
end
end
end

0 comments on commit a6c33c4

Please sign in to comment.