You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

oss-odm

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oss-odm

Object document mapper for Open Search Server.

0.2.0
Source
npmnpm
Version published
Weekly downloads
17
240%
Maintainers
1
Weekly downloads
 
Created
Source

oss-odm Build Status

Object document mapper for Open Search Server.

Install

npm install oss-odm

Usage

var oss = require('node-oss-client');
var Index = require('oss-odm').Index;

var index = new Index({
  name: 'my_index',
  indexers: oss.createClient(),
  searcher: oss.createClient()
});

// Insert a new document in "my_index".
index.create({ title: 'My first document' }, function (err) { ... });

// Search in "my_index".
index.search('my query', function (err, res) {
  console.log(res.documents); // [{ title: 'My first document' }]
});

new Index(options)

Create a new index with some options.

name

Type: String

Name of the index.

new Index({ name: 'my_index' });

lang

Type: String

Default language of the index, defaults to "ENGLISH".

new Index({
  lang: 'FRENCH'
});

indexers

Type: Array or Object

OSS clients used to index document.

var indexer1 = oss.createClient({ host: 'indexer1' });
var indexer2 = oss.createClient({ host: 'indexer2' });
new Index({ indexers: [indexer1, indexer2] });

searcher

Type: Object

OSS client used to search.

var searcher = oss.createClient({ host: 'searcher' });
new Index({ searcher: searcher });

templates

Type: Object

Search templates that can be used in index.search, the default template must be called "default". All search options known by OSS can be specified in the template.

new Index({
  templates: {
    default: {
      returnedFields: [
        'id',
        'title'
      ],
      searchFields: [
          {
            field: 'text',
            mode: 'TERM_AND_PHRASE',
            boost: 1
          }
      ]
    },
    title: {
      returnedFields: [
        'id',
        'title'
      ],
      searchFields: [
          {
            field: 'title',
            mode: 'TERM_AND_PHRASE',
            boost: 1
          }
      ]
    }
  }
});

formatters

Type: Object

You can specify an input (indexing) and an output (search) formatters. These formatter are applied to each documents.

new Index({
  formatters: {
    input: inputFormatter,
    output: outputFormatter
  }
});

function inputFormatter(document) {
  // Add a timestamp key.
  document.timestamp = Date.now();
  return document;
}

function outputFormatter(document) {
  // Convert id in Number.
  document.id = parseInt(document.id, 10);
  return document;
}

filters

Type: Object

Filters formatter that are used in index.search.

new Index({
  filters: {
    id: formatIdFilter
  }
});

function formatIdFilter(value, context) {
  return {
    type: 'QueryFilter',
    negative: false,
    query: 'id:' + value
  };
}

index.create(documents, [options], callback)

Insert a new document in the index.

index.create([
  { title: 'My first document' },
  { title: 'My second document' }
], function (err) { ... });

Some options are avalaibles:

lang

Type: String

The language of the document to index, default to the index language.

index.create([
  { title: 'My first document' }
], { lang: 'FRENCH' }, function (err) { ... });

index.search(query, [options], callback)

Search in the index.

``js index.search('my query', function (err, res) { ... });


Some options are avalaibles:

#### lang

Type: `String`

The language used for searching documents.

``js
index.search('my query', { lang: 'FRENCH' }, function (err, res) { ... });

template

Type: String

The template used to process the query, defaults to "default".

index.search('my query', { template: 'custom' }, function (err, res) { ... });

filters

Type: Object

Filters applied to the query. Filters are transformed using filter formatters defined in the constructor.

index.search('my query', {
  filters: {
    id: 10
  },
  filterOptions: {
    foo: 'bar'
  }
}, function (err, res) { ... });

OSS search options

All search options known by OSS can be used in the search function.

syncManager.sync(clients, schemas)

var indexer1 = oss.createClient({ host: 'indexer1' });
var indexer2 = oss.createClient({ host: 'indexer2' });

syncManager.sync([indexer1, indexer2], [
  {
    name: 'articles',
    uniqueField: 'id',
    defaultField: 'text',
    fields: [
      {
        name: 'id',
        indexed: true,
        stored: true
      },
      {
        name: 'text',
        indexed: true,
        stored: true
      }
    ]
  }
]);

syncManager.drop(clients, names)

var indexer1 = oss.createClient({ host: 'indexer1' });
var indexer2 = oss.createClient({ host: 'indexer2' });

syncManager.drop([indexer1, indexer2], ['articles']);

License

MIT

Keywords

oss

FAQs

Package last updated on 28 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts