Skip to content

Filter Unique Identifiers

Sébastien Cottinet edited this page Jun 15, 2021 · 4 revisions

Filter identifiers are unique hashes, dependant on the following:

This means that:

  • filter identifiers are stable, and they can be reusable: just provide the same random seed to each new Koncorde instance
  • since filters are transformed into a canonical form before a filter identifier is calculated, equivalent yet differently written filters will produce the same identifier

Example:

import { Koncorde } from 'koncorde';

const engine = new Koncorde();

// filter1 and filter2 are equivalent
const filterId1 = engine.register({
  and: [
    { equals: { firstname: 'Grace' } },
    { exists: { field: 'hobby' } },
  ]
});

const filterId2 = engine.register({
  not: {
    bool: {
      should_not: [
        { in: { firstname: [ 'Grace' ] } },
        { exists: { field: 'hobby' } },
      ],
    },
  },
});

// Prints:
// Are filter IDs equal: true
console.log(`Are filter IDs equal: ${filterId1 === filterId2}`);
Clone this wiki locally