Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Object document mapper for Open Search Server.
See also parent module node-oss-client.
npm install oss-odm
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' }]
});
Create a new index with some options.
Type: String
Name of the index.
new Index({ name: 'my_index' });
Type: String
Default language of the index, defaults to "ENGLISH".
new Index({
lang: 'FRENCH'
});
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] });
Type: Object
OSS client used to search.
var searcher = oss.createClient({ host: 'searcher' });
new Index({ searcher: searcher });
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
}
]
}
}
});
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;
}
Type: Object
Filters formatter that can be used in index.search
.
new Index({
filters: {
id: formatIdFilter
}
});
function formatIdFilter(value, context) {
return {
type: 'QueryFilter',
negative: false,
query: 'id:' + value
};
}
Type: Object
Joins that can be used in index.search
.
new Index({
joins: {
myJoin: {
index: customIndex,
queryTemplate: 'customQueryTemplate',
localField: 'local_id',
foreignField: 'id',
type: 'INNER',
returnFields: false,
returnScores: false,
eturnFacets: false
}
}
});
Insert a new document in the index.
Note : if an array is provided as value, it triggers a multi-valued field insertion.
index.create([
{
title: 'My first document',
foo: 'bar'
},
{
title: 'My second document',
ids: [23, 34]
}
], function (err) { ... });
Some options are available:
Type: String
The language of the document to index, default to the index language.
index.create([
{ title: 'My first document' }
], { lang: 'FRENCH' }, function (err) { ... });
Destroy a documents in the index.
index.destroy(['182', '85'], function (err) { ... });
Some options are available:
Type: String
The field used to match values, default to "id".
index.destroy(['bob', 'tom'], { field: 'name' }, function (err) { ... });
Search in the index.
index.search('my query', function (err, res) { ... });
Some options are available:
Type: String
The language used for searching documents.
index.search('my query', { lang: 'FRENCH' }, function (err, res) { ... });
Type: String
The template used to process the query, defaults to "default".
index.search('my query', { template: 'custom' }, function (err, res) { ... });
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) { ... });
Type: Object
Joins applied to the query. Joins used the joins defined in the constructor.
index.search('my query', {
joins: {
myJoin: {
query: 'join query',
template: 'myTemplate',
filters: {
myJoinFilter: 'test'
}
}
}
})
All search options known by OSS can be used in the search function.
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
}
]
}
]);
var indexer1 = oss.createClient({ host: 'indexer1' });
var indexer2 = oss.createClient({ host: 'indexer2' });
syncManager.drop([indexer1, indexer2], ['articles']);
MIT
FAQs
Object document mapper for Open Search Server.
The npm package oss-odm receives a total of 1 weekly downloads. As such, oss-odm popularity was classified as not popular.
We found that oss-odm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.