Skip to content

Commit

Permalink
[3100-highlight] When no highlighted field is available fall back int…
Browse files Browse the repository at this point in the history
…o the field value.

Co-authored-by: Jane Sandberg <[email protected]>
Co-authored-by: Vickie Karasic <[email protected]>
  • Loading branch information
3 people committed Nov 8, 2023
1 parent 157dd87 commit 1fafe70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
24 changes: 13 additions & 11 deletions app/services/blacklight/field_retriever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ def initialize(document, field_config, view_context = nil)

# @return [Array]
def fetch
Array.wrap(
if field_config.highlight
retrieve_highlight
elsif field_config.accessor
retieve_using_accessor
elsif field_config.values
retrieve_values
else
retrieve_simple
end
)
if field_config.highlight
value = retrieve_highlight
end
if value.blank?
value = if field_config.accessor
retieve_using_accessor
elsif field_config.values
retrieve_values
else
retrieve_simple
end
end
Array.wrap(value)
end

private
Expand Down
17 changes: 17 additions & 0 deletions spec/services/blacklight/field_retriever_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe Blacklight::FieldRetriever, api: true do
let(:service) { described_class.new(document, blacklight_field_config) }

let(:blacklight_field_config) { Blacklight::Configuration::Field.new(field: 'author_field', highlight: true) }
let(:document) { SolrDocument.new({ 'id' => 'doc1', 'title_field' => 'doc1 title', 'author_field' => 'author_someone' }, 'highlighting' => { 'doc1' => { 'title_tsimext' => ['doc <em>1</em>'] } }) }
let(:view_context) { {} }

context "highlighting" do
describe '#fetch' do
it "retrieves an author even if it's not highlighted" do
expect(service.fetch).to eq(['author_someone'])
end
end
end
end

0 comments on commit 1fafe70

Please sign in to comment.