Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

How to get the matching value with indexed array #383

Open
JF-Cozy opened this issue Mar 29, 2023 · 3 comments
Open

How to get the matching value with indexed array #383

JF-Cozy opened this issue Mar 29, 2023 · 3 comments

Comments

@JF-Cozy
Copy link

JF-Cozy commented Mar 29, 2023

When dealing with complex documents, it is recommanded to use a foo[]:bar syntax to index array attributes.

The problem is that you can't know which value of the array matched the search in the results. For example, if we have a list of contacts that may contain several email addresses { emails: [{address: 'toto@domain.com'}, {address: 'tata@domain.com'}] }, and we do a search on tata, the result will include emails[].address without us knowing which email address it is precisely.

Is there a way to overcome this? It would be nice to know which array value matched the search.

@JF-Cozy JF-Cozy changed the title Result when using arrays in indexed attributes How to get the matching value with indexed array Mar 30, 2023
@zanzlender
Copy link

zanzlender commented Apr 4, 2023

Did you set enrich=true when searching?

If yes then maybe you can try something like this if it works for you. I solved this like so:

E.g. I want to save a video transcript and search by keywords when something was said. And my file looks like so

type Transcript = {
  id: string;
  url: string;
  transcript: Array<{
    timestamp: string;
    transcript: string;
  }>;
};

And then I have the same problem as you. Because of that I loop over my array and create a object for each element which then looks like this

type FlexSearchDocument = {
  id: string;
  doc: {
    id: string;
    url: string;
    transcript: string;
    timestamp: string;
  };
};

In my case this is OK since what matters most is that I get the Id and Url. However, I can't yet estimate if the file is quickly getting big because of that...

@zanzlender
Copy link

Also, #358

@JF-Cozy
Copy link
Author

JF-Cozy commented Apr 5, 2023

No I didn't set enrich=true but tried with it, same problem so far. As the objects are quite big, and I already have them elsewhere, I prefer to keep only the ids.

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

No branches or pull requests

2 participants