@@ -41,17 +41,18 @@ def combine_highlights
4141
4242 def find_source_from_top_hits ( top_hits , field , key )
4343 # elasticsearch stores nested source results without the "path"
44+ parent = field . split ( "." ) . first
4445 nested_child = field . split ( "." ) . last
45- hit = top_hits . first . dig ( "_source" , nested_child )
46+ hit = top_hits . first . dig ( "_source" , parent ) . map { | i | i [ nested_child ] } . compact
4647 # if this is a multivalued field (for example: works or places),
4748 # ALL of the values come back as the source, but we only want
4849 # the single value from which the key was derived
4950 if hit . class == Array
5051 # I don't love this, because we will have to match exactly the logic
5152 # that got us the key to get this to work
52- match_index = hit
53- . map { |s | remove_nonword_chars ( s ) }
54- . index ( remove_nonword_chars ( key ) )
53+ match_index = hit
54+ . map { |s | remove_nonword_chars ( s ) }
55+ . index ( remove_nonword_chars ( key ) )
5556 # if nothing matches the original key, return the entire source hit
5657 # should return a string, regardless
5758 return match_index ? hit [ match_index ] : hit . join ( " " )
@@ -72,7 +73,8 @@ def format_bucket_value(facets, field, bucket)
7273 # Example: "Willa Cather" and "WILLA CATHER"
7374 # Those terms will both have been normalized as "willa cather" but
7475 # we will want to display one of the non-normalized terms instead
75- top_hits = bucket . dig ( "top_matches" , "hits" , "hits" )
76+
77+ top_hits = bucket . dig ( "field_to_item" , "top_matches" , "hits" , "hits" )
7678 if top_hits
7779 source = find_source_from_top_hits ( top_hits , field , key )
7880 end
0 commit comments