-
Notifications
You must be signed in to change notification settings - Fork 4
Home
This module is a reverse-search engine.
Instead of indexing data and searching for them using filters, Koncorde does the opposite: it indexes search filters, and returns the corresponding ones when presented with data.
- an arbitrary large number of filters can be registered and indexed;
- whenever data are submitted to Koncorde, it returns the list of indexed filters matching them.
Koncorde can be used in a variety of ways. For instance:
- as a base of a notification system, where indexed filters are used as user subscriptions: Koncorde tells which JSON objects verify what subscriptions, making it easy to send events to listening users;
- to verify if JSON objects comply to filters used as validation rules.
Example:
In the following example, we'll listen to objects containing a position
property, describing a geopoint. We want that geopoint to be 500 meters around a pre-defined starting position.
This can be described by the following Koncorde filter:
{
"geoDistance": {
"position": {
"lat": 43.6073913,
"lon": 3.9109057
},
"distance": "500m"
}
}
All you need to do now is to register this filter to the engine, and use it to test data:
import { Koncorde } from 'koncorde';
const engine = new Koncorde();
const filter = {
geoDistance: {
position: {
lat: 43.6073913,
lon: 3.9109057
},
distance: "500m"
}
};
const filterId = engine.register(filter);
// Filter Identifiers are stable, more on that in the appropriate
// chapter.
// Prints '869dd9dd65290278ce2a847650313761'
console.log(`Filter identifier: ${filterId}`);
// *** Now, let's test data with our engine ***
// Returns an empty array (distance is greater than 500m)
console.log(engine.test({ position: { lat: 43.6073913, lon: 5.7 } }));
// Returns: ['869dd9dd65290278ce2a847650313761']
console.log(engine.test({ position: { lat: 43.608, lon: 3.905 } }));
// Returns an empty array (the geopoint is not stored in a "position" field)
console.log(engine.test({ point: { lat: 43.608, lon: 3.905 } }));
This library is compatible with Node.js version 12.x or higher. Both a C and a C++ compilers are needed to install its dependencies: Koncorde cannot be used in a browser.
Koncorde is compatible with either Javascript or Typescript projects.
To install:
npm install --save koncorde