Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Grouped Hits not compatible with react-instantsearch Highlight element #184

Open
RBSUS opened this issue Sep 1, 2023 · 2 comments
Open

Comments

@RBSUS
Copy link

RBSUS commented Sep 1, 2023

Description

The terms that are expected to be highlighted from the query string are not highlighted when I pass a hit from _grouped_hits into the react-instant Highlight element. The top level hit works fine as the matched query string appears highlighted, yet the hits within _grouped_hits instead display the matched term wrapped in a new string 'ais_highlight'

Expected Behavior

image

Actual Behavior

image

Metadata

"typesense": "^1.0.2",
"typesense-instantsearch-adapter": "^2.7.1",
"react-instantsearch": "^7.0.1",

OS: Windows

@RBSUS RBSUS changed the title Grouped Hits not compatible with react-instant Highlight element Grouped Hits not compatible with react-instantsearch Highlight element Sep 1, 2023
@jasonbosco
Copy link
Member

I just tested this in a demo project and it seems to work fine for me.

Could you share a simple project that replicates the issue?

@m0ppers
Copy link

m0ppers commented Jul 15, 2024

I have the same problem (but using vue). using adapter v2.8.0. this is my current workaround:

const transformItems = (items) => {
  // fix snippet containing __ais-highlight__ tags https://github.com/typesense/typesense-instantsearch-adapter/issues/184
  return items.map((item) => {
    item._grouped_hits = item._grouped_hits.map((hit: any) => {
      // unclear why this is necessary
      if (!hit._rawTypesenseHit.highlight.text) {
        return hit;
      }
      hit._snippetResult.text.value =
        hit._rawTypesenseHit.highlight.text.snippet;
      return hit;
    });
    return item;
  });
};

Sorry. No time right now to share a demoproject. This is my adapter config:

const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
  server: {
    apiKey: "xyz", // Be sure to use the search-only-api-key
    nodes: [
      {
        host: "localhost",
        port: 8108,
        protocol: "http",
      },
    ],
  },
  additionalSearchParameters: {
    query_by: "text",
    group_by: "filename",
  },
  flattenGroupedHits: false,
});

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants