@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 { DefaultClient, FieldMode } = require("@sajari/sdk-node");
const client = new DefaultClient("<project>", "<collection>", {
key: "<key from console>",
secret: "<secret from console>"
});
const schema = client.schema()
const fields = [
schema.boolean("my-boolean-field", {
mode: FieldMode.Required
}),
schema.string("text")
]
schema.add(...fields).catch(error => {})
Adding a record
const { DefaultClient } = require("@sajari/sdk-node");
const client = new DefaultClient("<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 { DefaultClient, DefaultSession, TrackingType } = require("@sajari/sdk-node");
const client = new DefaultClient("<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