0.0.1 • Published 8 months ago

desearch v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

unsearch

A set of adapters for working with common search engines like Algolia, Meilisearch, ElasticSearch, Typesense and Fuse.js

🚧 In active development, don't use yet 🚧

Usage

Initialize an index with an adapter, for example Algolia:

import { Index, Algolia } from 'unsearch'

// define schema of document
interface Document {
  id: string // id field is required

  // remaining fields can be anything
  path: string
  content: string
}

const index = new Index<Document>({
  adapter: new Algolia({
    index: 'my-index-name',
    credentials: {
      appId: '...',
      apiKey: '...'
    }
  })
})

Submit documents for indexing:

const documents: Document[] = [
  { id: 'welcome', path: '/welcome', content: ... },
  { id: 'getting-started', path: '/start', content: ... },
]

await index.submit(documents)

Search the index for matching docs:

const matches = await index.search('hello')

Can also filter the index while searching:

const matches = await index.search('hello', {
  filters: [
    or(
      eq('tags', 'js'),
      eq('tags', 'rust')
    )
  ]
})

License

MIT

0.0.1

8 months ago