@@ -41,17 +41,18 @@ def combine_highlights
41
41
42
42
def find_source_from_top_hits ( top_hits , field , key )
43
43
# elasticsearch stores nested source results without the "path"
44
+ parent = field . split ( "." ) . first
44
45
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
46
47
# if this is a multivalued field (for example: works or places),
47
48
# ALL of the values come back as the source, but we only want
48
49
# the single value from which the key was derived
49
50
if hit . class == Array
50
51
# I don't love this, because we will have to match exactly the logic
51
52
# 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 ) )
55
56
# if nothing matches the original key, return the entire source hit
56
57
# should return a string, regardless
57
58
return match_index ? hit [ match_index ] : hit . join ( " " )
@@ -72,7 +73,8 @@ def format_bucket_value(facets, field, bucket)
72
73
# Example: "Willa Cather" and "WILLA CATHER"
73
74
# Those terms will both have been normalized as "willa cather" but
74
75
# 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" )
76
78
if top_hits
77
79
source = find_source_from_top_hits ( top_hits , field , key )
78
80
end
0 commit comments