Match highlight plugin
The plugin-match-highlight plugin allows Orama to keep track of all token positions on each property of each document.
Installation
You can install the plugin using any major Node.js package manager.
Usage
Plugin usage depends on the runtime that you are using, even though the goal is to expose the exact same APIs for browsers, Deno, and all the other JavaScript engines.
The plugin exports afterInsertHook
, which will be the hook used by Orama to add positions, and searchWithHighlight
which wraps the original Orama’s search
function to return positions alongside docs.
This will add the positions
property to each hit
:
Saving Database State with Highlights
Orama exposes a save
method, which is used to persist its state either in-memory or on disk.
By default, it doesn’t save the highlights exposed by this plugin. If you need them, you can easily handle this case by using the saveWithHighlight
and loadWithHighlight
functions:
CommonJS Imports
Orama plugins ship ESM modules by default. This allows us to move faster when providing new features and bug fixes, as well as using the "exports"
field in package.json
to provide a better developer experience.
CommonJS imports are still supported, but we suggest you to migrate to ESM.
TypeScript
Set moduleResolution
in the compilerOptions
in your tsconfig.json
to be either Node16
or NodeNext
.
When importing types, always refer to the standard import: