askorama / orama

🌌 Fast, dependency-free, full-text and vector search engine with typo tolerance, filters, facets, stemming, and more. Works with any JavaScript runtime, browser, server, service!
https://docs.askorama.ai
Other
8.27k stars 273 forks source link

plugin-match-highlight does not work with array field #669

Closed matijagaspar closed 3 months ago

matijagaspar commented 3 months ago

Describe the bug

The plugin ignores array fields in the schema, so matches found inside string arrays do not list highlight positions

To Reproduce

import { create, insert } from '@orama/orama'
import { afterInsert as highlightAfterInsert, searchWithHighlight } from '@orama/plugin-match-highlight'
const db = await create({
  schema: {
    arrayToSearch: 'string[]'
  },
  plugins: [
    {
      name: 'highlight',
      afterInsert: highlightAfterInsert
    }
  ]
})

await insert(db, { arrayToSearch: ['hello world', 'world hello'] })

const results = await searchWithHighlight(db, {
  term: 'hello'
})

Results hits.positions being {}:

Expected behavior

positions object in the hit to not be empty.

Environment Info

OS: Ubuntu 22.04.4 LTS
Node: v18.12.1
Orama: 2.0.11

Affected areas

Search

Additional context

No response

jblyberg commented 3 months ago

You should submit your change as a pull request. I'm interested in this functionality as well.

jblyberg commented 3 months ago

Also noticed that the result doesn't filter array strings that don't have a hit. This is kind of important when building search objects that need to query relations.

micheleriva commented 3 months ago

Hi folks, I have an update on this. We're gonna deprecate this plugin in favor of https://www.npmjs.com/package/@orama/highlight. This allows more lightweight and faster indexes, I highly recommend using it.