Skip to main content
This plugin is deprecated. Please use @orama/highlight instead.

Deprecation Notice

The Match Highlight Plugin has been deprecated in favor of the new @orama/highlight package, which offers:
  • Better Performance: Faster highlighting with lower memory footprint
  • Easier to Use: Simpler API and integration
  • More Features: Advanced highlighting options
  • Active Maintenance: Continued support and updates

Migration Guide

Old Approach (Deprecated)

import { create, insert } from '@orama/orama'
import { searchWithHighlight, afterInsert } from '@orama/plugin-match-highlight'

const db = await create({
  schema: {
    title: 'string',
    description: 'string'
  },
  plugins: [{
    name: 'match-highlight',
    afterInsert
  }]
})

await insert(db, {
  title: 'Wireless Headphones',
  description: 'Premium noise-cancelling headphones'
})

const results = await searchWithHighlight(db, {
  term: 'headphones'
})
npm install @orama/highlight
import { create, insert, search } from '@orama/orama'
import { highlight } from '@orama/highlight'

const db = await create({
  schema: {
    title: 'string',
    description: 'string'
  }
})

await insert(db, {
  title: 'Wireless Headphones',
  description: 'Premium noise-cancelling headphones'
})

// Perform search
const results = await search(db, {
  term: 'headphones'
})

// Highlight matches in results
const highlighted = results.hits.map(hit => ({
  ...hit,
  document: {
    ...hit.document,
    title: highlight(hit.document.title, 'headphones'),
    description: highlight(hit.document.description, 'headphones')
  }
}))

Why Use @orama/highlight?

Performance

10x faster highlighting with minimal memory usage

Simplicity

No plugin configuration required, just call the function

Flexibility

Customizable highlighting with HTML or custom markers

Maintained

Active development and regular updates

@orama/highlight Features

Basic Highlighting

import { highlight } from '@orama/highlight'

const text = 'Wireless headphones with noise cancelling'
const highlighted = highlight(text, 'headphones')
// "Wireless <mark>headphones</mark> with noise cancelling"

Custom HTML Tags

const highlighted = highlight(text, 'headphones', {
  tag: 'strong',
  className: 'search-match'
})
// "Wireless <strong class=\"search-match\">headphones</strong> with noise cancelling"

Case Insensitive

const highlighted = highlight('Wireless Headphones', 'headphones', {
  caseSensitive: false
})
// "Wireless <mark>Headphones</mark>"

Multiple Terms

const highlighted = highlight(text, ['wireless', 'headphones'])
// "<mark>Wireless</mark> <mark>headphones</mark> with noise cancelling"

Documentation

For full documentation on @orama/highlight, visit:

Legacy Plugin Reference

If you must continue using the deprecated plugin, here’s the basic API:

Installation

npm install @orama/plugin-match-highlight

API

afterInsert()

Plugin hook that stores position information for each inserted document.
async function afterInsert<T extends AnyOrama>(
  orama: T,
  id: string
): Promise<void>

searchWithHighlight()

Performs a search and returns results with position information.
async function searchWithHighlight<T extends AnyOrama, ResultDocument = TypedDocument<T>>(
  orama: T,
  params: SearchParamsFullText<T, ResultDocument>,
  language?: Language
): Promise<SearchResultWithHighlight<ResultDocument>>

saveWithHighlight()

Saves the Orama instance including position data.
function saveWithHighlight<T extends AnyOrama>(
  orama: T
): RawDataWithPositions

loadWithHighlight()

Loads an Orama instance including position data.
function loadWithHighlight<T extends AnyOrama>(
  orama: T,
  raw: RawDataWithPositions
): void

Support

The Match Highlight Plugin will receive no further updates. Please migrate to @orama/highlight for continued support.
For issues or questions:

Next Steps

@orama/highlight

Install the new highlighting package

Search Guide

Learn more about search in Orama

Build docs developers (and LLMs) love