Skip to content

Named Indexes

Sébastien Cottinet edited this page Jun 9, 2021 · 3 revisions

By default, Koncorde stores filters in an unnamed index.

Multiple indexes can be used to store and match filters in an independant way, using the index option.

This option can be used to organize filters in different, independant search scopes.

Example

const { Koncorde } = import 'koncorde';

const engine = new Koncorde();
const filter = { equals: { foo: 'bar' } };

// Uses the default index
const defid = engine.register(filter);

// Named indexes
const idx1id = engine.register(filter, 'index1');
const idx2id = engine.register(filter, 'index2');

// Prints different filter IDs because the filter is stored
// in different indexes:
// {
//   defid: '24f181026bb02ac7aff32dd3b9c1c4d5',
//   idx1id: '14b092e24a86567ca6c883a063e305b4',
//   idx2id: '5d20fc1304be73554913d0e76758d10b'
// }
console.dir({ defid, idx1id, idx2id });

// Tests only filters indexed in the default index.
// Prints: [ '24f181026bb02ac7aff32dd3b9c1c4d5' ]
console.log(engine.test({ foo: 'bar' }));

// Tests only filters indexed in the named index 'index1'
// Prints: [ '14b092e24a86567ca6c883a063e305b4' ]
console.log(engine.test({ foo: 'bar' }, 'index1'));

// Tests only filters indexed in the named index 'index2'
// Prints: [ '5d20fc1304be73554913d0e76758d10b' ]
console.log(engine.test({ foo: 'bar' }, 'index2'));
Clone this wiki locally