@sajari/sdk-node
Node.js SDK for Sajari APIs
Getting Started
Installation
This is a Node.js module available through the
npm registry. It can be installed using the
npm
or yarn
command line tools.
npm install @sajari/sdk-node --save
Tests
npm install
npm test
Examples
Creating a schema
const { Client, FieldMode, schema } = require("@sajari/sdk-node");
const client = new Client("<project>", "<collection>", {
key: "<key from console>",
secret: "<secret from console>"
});
const fields = [
schema.field.boolean("my-boolean-field", {
mode: FieldMode.Required
}),
schema.field.string("text")
]
client.schema().add(...fields).catch(error => {})
Adding a record
const { Client } = require("@sajari/sdk-node");
const client = new Client("<project>", "<collection>", {
key: "<key from console>",
secret: "<secret from console>"
});
const pipeline = client.pipeline("<your pipeline name>")
const record = {
"my-boolean-field": true,
"text": "hello"
}
pipeline.add({}, record)
.then(key => {})
.catch(error => {})
Performing a search
const { Client, DefaultSession, TrackingType } = require("@sajari/sdk-node");
const client = new Client("<project>", "<collection>", {
key: "<key from console>",
secret: "<secret from console>"
});
const session = new DefaultSession(TrackingType.None);
const pipeline = client.pipeline("<your pipeline name>");
const values = { q: "hello" };
pipeline.search(values, session.next(values))
.then(response => {})
.catch(error => {})
License
MIT