Skip to main content

Search

The Toolkit ships with the package @jsplumbtoolkit/search, which offers a reverse text search engine on the contents of each of the nodes/groups/edges in a given Toolkit instance.

Installation

npm i @jsplumbtoolkit/search

Usage

Using the search package is straightforward:

import { Index } from "@jsplumbtoolkit/search"
import { newInstance } from "@jsplumbtoolkit/browser-ui-vanilla"

const tk = newInstance()
const index = new Index(tk)

At this point we have an instance of the search index, linked to the given Toolkit instance. The search index exposes a single search(s:string) method:


tk.addNode({id:"1", foo:"bar"})

const results = index.search("bar")

results is an object of type jsPlumbToolkitSearchResults:

Home > @jsplumbtoolkit/search > jsPlumbToolkitSearchResults

jsPlumbToolkitSearchResults type

Signature:

export declare type jsPlumbToolkitSearchResults = {
nodes: Array<Node>;
groups: Array<Group>;
edges: Array<Edge>;
ports: Array<Port>;
};

Options

In the code snippets shown above, we instantiate a search index with all of its defaults. But the search index constructor takes an optional second argument containing options for the index. The options type is:

Home > @jsplumbtoolkit/search > jsPlumbToolkitSearchIndexOptions

jsPlumbToolkitSearchIndexOptions interface

Options for the search index.

Signature:

export interface jsPlumbToolkitSearchIndexOptions 

Properties

PropertyModifiersTypeDescription
caseSensitive?boolean(Optional) Whether or not the search index should ignore case. By default this is false.
exclusions?Array<string>(Optional) Optional list of field names to omit from the documents stored for each node. This means that any field in this list will not be indexed.
fields?Array<string>(Optional) Optional list of fields to index. By default this is empty, meaning all fields (minus any exclusions) will be indexed.
limit?number(Optional) Optional limit for the number of result a search should return. Defaults to 10.