Miscellaneous / Text search

Text Search

From version 1.17.0 onwards, the Toolkit ships with an optional text search index.

Installation

The text index ships as a separate package, in the file jsplumbtoolkit-search.tgz. You can import it as a local file reference:

{
    "dependencies":{
        ...
        "jsplumbtoolkit-search":"file:path/to/jsplumbtoolkit-search.tgz",
        ...        
    }
}

If you're using Angular or Webpack/Rollup etc, this should suffice for it to appear in your output bundle. If you're more of a traditionalist and you're including scripts individually, you'll find it at:

<script src="./node_modules/jsplumbtoolkit-search/dist/js/jsplumbtoolkit-search.js"></script>

Setup

You'll first need to create an instance of the Toolkit. Then you can create a search index like this:

const index = new jsPlumbToolkitSearch(toolkitInstance);

What gets indexed?

The indexer indexes the backing data for all nodes, ports, groups and edges. Only string values are indexed, though, for instance in this dataset:

{
    foo:"some string",
    foos:[ "some", "strings" ]
}

Only the value for key foo is indexed. The array corresponding to key foos is not indexed.

Usage

A quick example:

var tk = jsPlumbToolkit.newInstance();
tk.addNode({id:"1", foo:"FOO"});
tk.addNode({id:"2", foo:"BAR"});
tk.addEdge({source:"1", target:"2", data:{id:"1", foo:"EDGE FOO"}});

var index = new jsPlumbToolkitSearch(tk);
var results = index.search("FOO");

Here, results would have this value:

{
    nodes:[ node1 ],
    edges: [ edge 1 ],
    ports: [],
    groups: []
}

where node1 and edge1 are the corresponding object from the Toolkit, of types Node and Edge respectively.