Coder Social home page Coder Social logo

swiftype-node's Introduction

Node.js client for the Swiftype API

Build Status

Installation

With npm:

npm install swiftype

or clone locally:

$ git clone [email protected]:swiftype/swiftype-node.git
$ cd swiftype-node
$ npm install

Examples

Create a new instance of the client with your api key:

var SwiftypeApi = require('swiftype')
var swiftype = new SwiftypeApi({
  apiKey: 'yourApiKey'
})

Searching

Search for cats on the engine my-engine:

swiftype.search({
  engine: 'my-engine',
  q: 'cats'
}, function(err, res) {
  console.log(res)
})

Documents

Create a new document:

swiftype.documents.create({
  engine: 'my-engine',
  documentType: 'books',
  document: {
    external_id: '1',
    fields: [
      { name: 'title', value: 'The Great Gatsby', type: 'string' },
      { name: 'author', value: 'F. Scott Fitzgerald', type: 'string' },
      { name: 'genre', value: 'fiction', type: 'enum' }
    ]
  }
}, function(err, res) {
  console.log(res)
})

Engines

Fetch all of your engines:

swiftype.engines.list(function(err, res) {
  console.log(res)
})

Fetch a single engine:

swiftype.engines.get({
  engine: 'my-engine'
}, function(err, res) {
  console.log(res)
})

Document Types

Fetch all of the document types in the engine my-engine

swiftype.documentTypes.list({
  engine: 'my-engine'
}, function(err, res) {
  console.log(res)
})

Fetch the document type books in the engine my-engine

swiftype.documentTypes.get({
  engine: 'my-engine', 
  documentType: 'books'
}, function(err, res) {
  console.log(res)
})

Check out the tests for more examples!

Tests

$ npm test

The tests use stubbed HTTP interactions that are recorded with the node-replay module. By default, HTTP interactions are not allowed when running the tests.

swiftype-node's People

Contributors

mikesea avatar trek avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.