Another one ... anyone has a few examples of how t...
# community-help
m
Another one ... anyone has a few examples of how they integrated highlights? Seems very cumbersome at this stage to be fair. I have a full blown result in the search overview, with the bigger dataset as above, but to replace fields/data if/when there is a hit seems weird. Isn't there a possibility to add the highlight in the actual returned field, or at least a reference towards it? @Kishore Nallan @Jason Bosco 🤔
d
Typesense returns
highlights
for each found hit, you can see it in the example response
Or I get you wrong and you wanted to see highlighted snippet right in the
document
?
m
I would like it in the document @Dima, well aware it returns a highlights object, but if you have multiple fields you could have a possible hit on, it's cumbersome to code all kinds of defensiveness in there just in case the field you want to show doesn't contain a highlight. It's like a mix and match puzzle currently.
👍 1
j
Could you elaborate on the cumbersome-ness? I usually do
hit.highlight.fieldX?.value || hit.document.fieldX
in JS for eg to check if a highlight exists for a field, if not fallback to the unhighlighted field
m
I'll try it that way @Jason Bosco thanks for the suggestion. I'll get back to you, on first sight it seemed the highlight structure is slightly different than the actual document fields.
j
There is an older
highlights
key in the response which has a different structure (we’ll be deprecating it in a future version, but just keeping it around for backward compatibility). Instead you want to use the new
highlight
(singular) key (as of v0.24.1) which should be much easier to parse
🙌 1