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

searchWithHighlight crashes after persistence restore #446

Closed
nekdolan opened this issue Jul 15, 2023 · 6 comments · Fixed by #471
Closed

searchWithHighlight crashes after persistence restore #446

nekdolan opened this issue Jul 15, 2023 · 6 comments · Fixed by #471

Comments

@nekdolan
Copy link

Describe the bug
When db is restored using data persistence plugin the search with higlight functionality no longer works

To Reproduce
Steps to reproduce the behavior:

  • Add presistence plugin
  • Add match highlight plugin
  • Insert documents
  • call persist
  • call restore
  • call searchWithHighlight

Expected behavior
not crash with error

Screenshots

const db = await create({
        schema: {
            // id: 'string',
            text: 'string',
            name: 'string',
            type: 'string',
            year: 'number',
            source: 'string',
            author: 'string'
        },
        components: {
            // Register the hook
            afterInsert: [highlightAfterInsert],
            tokenizer: {
                stopWords: englishStopwords,
                stemming: true,
                stemmer
            },
        }
    })
TypeError: Cannot read properties of undefined (reading '21650872-55')          1:49:20 PM
    at file:///Users/trinimac/WebstormProjects/lazarites/node_modules/@orama/plugin-match-highlight/dist/index.js:52:78
    at Array.map (<anonymous>)
    at searchWithHighlight (file:///Users/trinimac/WebstormProjects/lazarites/node_modules/@orama/plugin-match-highlight/dist/index.js:51:30)
    at async cachedEventHandler.swr (file:///Users/trinimac/WebstormProjects/lazarites/.nuxt/dev/index.mjs:5363:21)
    at async file:///Users/trinimac/WebstormProjects/lazarites/.nuxt/dev/index.mjs:1584:20
    at async _resolve (file:///Users/trinimac/WebstormProjects/lazarites/.nuxt/dev/index.mjs:1445:23)

Desktop (please complete the following information):

  • NodeJS Nuxt 3 server
@allevo
Copy link
Collaborator

allevo commented Jul 17, 2023

Hi, thank you for opening this issue!
Which version of Orama are you using for dumping and searching?
Which version of Orama persistence & highlight plugins are you using?
I suggest you to use the same version everywhere

@micheleriva
Copy link
Member

Hi @nekdolan any update on the above questions from @allevo above?

@benjaminleonard
Copy link
Contributor

I am seeing this too, not with Orama persistence but I have my own code for retrieving it from json.

"@orama/plugin-match-highlight": "^1.2.1",
"@orama/orama": "^1.2.1",

@benjaminleonard
Copy link
Contributor

benjaminleonard commented Aug 25, 2023

I believe the issue might be in the save() function. If I don't use that I can see "positions" in the output, but it's not in what is returned from save()

Looks like it's missing from here:

export async function save(orama: Orama): Promise<RawData> {
return {
internalDocumentIDStore: orama.internalDocumentIDStore.save(orama.internalDocumentIDStore),
index: await orama.index.save(orama.data.index),
docs: await orama.documentsStore.save(orama.data.docs),
sorting: await orama.sorter.save(orama.data.sorting),
language: orama.tokenizer.language,
}
}

@benjaminleonard
Copy link
Contributor

benjaminleonard commented Aug 25, 2023

Perhaps something like this within @orama/plugin-match-highlight:

export type RawDataWithPositions = RawData & {
  positions: Record<string, Record<string, Record<string, Position[]>>>
}

export async function saveWithHighlight(
  orama: OramaWithHighlight,
): Promise<RawDataWithPositions> {
  const data = await save(orama)

  return {
    ...data,
    positions: orama.data.positions,
  }
}

Edit: I figured that would fix the issue but I am still getting the error even when positions is present

@benjaminleonard
Copy link
Contributor

benjaminleonard commented Aug 30, 2023

I think I have it working, but there seems to be an issue in the load() function. It's not adding the positions object. My example works with:

export async function loadWithHighlight(
  orama: OramaWithHighlight,
  raw: RawDataWithPositions,
): Promise<void> {
  await loadOramaDB(orama, raw)
  orama.data.positions = raw.positions
}

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

Successfully merging a pull request may close this issue.

4 participants