Skip to content

nnstd/bright-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bright Logo
TypeScript/JavaScript client library for Bright full-text search database.

Installation

npm install bright-client
# or
yarn add bright-client
# or
pnpm add bright-client
# or
bun add bright-client

Usage

Create a Client

import { createClient } from 'bright-client';

const client = createClient({
  baseUrl: 'http://localhost:3000'
});

Index Management

// Create an index
await client.createIndex('products', 'id');

// Update index configuration
await client.updateIndex('products', { primaryKey: 'sku' });

// Delete an index
await client.deleteIndex('products');

Document Operations

// Add documents
await client.addDocuments('products', [
  { id: '1', name: 'Widget', price: 19.99 },
  { id: '2', name: 'Gadget', price: 29.99 }
]);

// Update a document
await client.updateDocument('products', '1', { price: 24.99 });

// Delete a document
await client.deleteDocument('products', '1');

// Delete multiple documents
await client.deleteDocuments('products', { ids: ['1', '2'] });

// Delete by filter
await client.deleteDocuments('products', { filter: 'category:electronics' });

Search

// Simple search
const results = await client.search('products', {
  q: 'laptop'
});

// Advanced search with options
const results = await client.search('products', {
  q: 'laptop',
  limit: 20,
  page: 1,
  sort: ['-price', 'name'],
  attributesToRetrieve: ['id', 'name', 'price']
});

// Search with TypeScript types
interface Product {
  id: string;
  name: string;
  price: number;
}

const results = await client.search<Product>('products', {
  q: 'laptop'
});

console.log(results.hits); // Product[]
console.log(results.totalHits); // number
console.log(results.totalPages); // number

License

MIT

About

A JavaScript client for Bright search-engine

Resources

License

Stars

Watchers

Forks

Packages

No packages published