#community-help

Integration Issues with Highlights in Typesense

TLDR Michael was struggling with integrating highlights into their work. Dima and Jason offered clarifications and suggestions. Michael decided to try Jason's solution.

Powered by Struct AI

1

1

Aug 07, 2023 (4 months ago)
Michael
Photo of md5-ab9a5d60cb7ebd0211d1a368b45a0473
Michael
02:07 PM
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 :thinking_face:
Dima
Photo of md5-1b62114a658b760944aa7d2b4c274460
Dima
02:28 PM
Typesense returns highlights for each found hit, you can see it in the example response
02:29
Dima
02:29 PM
Or I get you wrong and you wanted to see highlighted snippet right in the document?
Michael
Photo of md5-ab9a5d60cb7ebd0211d1a368b45a0473
Michael
02:56 PM
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

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:39 PM
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
Aug 08, 2023 (4 months ago)
Michael
Photo of md5-ab9a5d60cb7ebd0211d1a368b45a0473
Michael
07:12 AM
I'll try it that way Jason 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.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:12 PM
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