Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds config setting index_tsim_only_threshold #964

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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