node-manticoresearch
v0.0.7
Published
Simple, Light, Promise
Downloads
24
Readme
This is a Node.js client for ManticoreSearch. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.
const manticoresearch = require('node-manticoresearch');
const ms = manticoresearch(); // default (localhost)
const ms = manticoresearch(9308, '100.100.100.100'); // custom
//---]>
// return { data: ..., response: ... }
SQL SELECT query via HTTP JSON interface:
const raw = false; // default
const r = await ms.sql(`SELECT * FROM items`, raw);
console.log(r.data);
- HINT: simple SQL escape - sqlstring
Bulk:
const r = await ms
.insert('items')
.bulk([
// switch 'insert' to 'update'
// { id: 0, action: 'update', doc: { title: 'Hello #1' }},
{ doc: { a: 1, b: 2, title: 'Hello #1' }},
{ doc: { a: 1, b: 2, title: 'World #1' }},
{ id: 1, doc: { a: 3, b: 4, title: 'Qwerty #1' }}
]);
console.log(r.data?.items);
Search:
const r = await ms
.search('items')
.pagination(1, 3) // .limit(size).offset(page * size)
.query({ match: { title: 'world' } });
console.log(r.data?.hits);
Nested bool query:
const r = await ms
.search('items')
.query((q) => q.and([
q.is('a', 1),
q.or([
q.is('a', 1),
q.is('b', 2)
]),
q.match('title', 'world')
]));
console.log(r.data?.hits);
// SELECT * FROM items
// WHERE a = 1 and (a = 1 or b = 2) and MATCH('@title world')
Nested bool query (short):
const r = await ms
.search('items')
.query(_ => _.and(
['a', 0],
_.or(['a', 1], ['b', 2]),
_.match('title', 'world')
));
console.log(r.data?.hits);
// SELECT * FROM items
// WHERE a = 1 and (a = 1 or b = 2) and MATCH('@title world')
Delete by Id:
const r = await ms
.delete('items')
.call('9865535'); // number, string, bigInt
console.log(r.data);
Delete by Query:
const r = await ms
.delete('items')
.query({ match: { title: 'hello' } });
console.log(r.data);
Delete all:
const r = await ms
.delete('items')
.call();
console.log(r.data);
Insert:
const id = 0; // auto
const r = await ms
.insert('items')
.call(id, { doc: { a: 4, b: 4, title: 'hi #1' }});
console.log(r.data);
License
MIT