#community-help

Issue with escapeHTML and Search Highlighting

TLDR Digamber is having trouble with the search highlighting not working when escapeHTML is set to false. Kishore Nallan and Jason try to help but the issue remains unresolved.

Powered by Struct AI
Dec 14, 2021 (23 months ago)
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
10:32 AM
My main issue is that whenever i set escapteHTML: false - the highlighting isn’t working
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:33 AM
Can you show a sample record and the response?
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
10:46 AM
instantSearch.addWidgets([
            searchBox({
                container: searchBoxEl[0],
                autofocus: true,
                placeholder: 'Search...',
                showSubmit: false,
                showReset: false,
            }),
            configure({
                hitsPerPage: config.per_page,
            }),
            hits({
                container: defaultSearchResultEl[0],
                escapeHTML: false,
                templates: {
                    item: `
      <h2>
        {{ __hitIndex }}:
        {{#helpers.highlight}}{ "attribute": "post_content" }{{/helpers.highlight}}
      </h2>
      <p>{{ post_description }}</p>
    `,
                },
            }),

        ]);
10:47
Digamber
10:47 AM
This is the code i used
10:47
Digamber
10:47 AM
the result is
10:48
Digamber
10:48 AM
10:49
Digamber
10:49 AM
Whereas if i set escapeHTML to false - it works as expected.
10:50
Digamber
10:50 AM
As you can see I need to escape html as the content is html
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:43 AM
Ok I will run this through another pair of eyes, for help.
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
11:47 AM
Thanks Kishore appreciate it
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:35 PM
Digamber could you try using JS instead of liquid like this and see if that helps: https://github.com/typesense/showcase-linux-commits-search/blob/82267196edc95f3f737af9d8374d0cf720892910/src/app.js#L191
Dec 15, 2021 (23 months ago)
Digamber
Photo of md5-a0246423746b3b51425d05cfd9c494ae
Digamber
04:21 AM
Jason no luck i’m still having the same issue
04:48
Digamber
04:48 AM
i had to strip the html before entry into document - for my use case it currenlty works - but was wondering if having html would be bennefitial