Lyra

Fast, typo-tolerant, full-text search engine written in TypeScript.

An example usage of Lyra

Built & sponsored by

Why?

Lyra is a modern, dependency-free full-text search engine written in TypeScript.
It has been built with speed in mind and completes most search lookups in a few microseconds.

It implements a very fast, vanilla prefix tree to perform efficient lookups and easy serialization with multiple formats, such as dpack and protocol buffers.

Its main focus is to be able to run on edge networks, such as AWS Lambda@Edge, Cloudflare Workers, and Netlify Functions, so expect some updates on that.

It was named after the Lyra constellation due to its distributed and highly scalable nature.

Quickstart

Install Lyra

yarn add @nearform/lyra

Create a new database

import { create } from '@nearform/lyra'
const db = create({
  schema: {
    quote: 'string',
    author: 'string'
  }
})

Insert data

import { create, insert } from '@nearform/lyra'

insert(db, {
  quote: 'It is during our darkest moments that we must focus to see the light.',
  author: 'Aristotle'
});

insert(db, {
  quote: 'If you really look closely, most overnight successes took a long time.',
  author: 'Steve Jobs'
});

insert(db, {
  quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.',
  author: 'Jim Rohn'
});

insert(db, {
  quote: 'You miss 100% of the shots you don\'t take',
  author: 'Wayne Gretzky - Michael Scott'
});

Search for data

import { create, insert, search } from '@nearform/lyra'

const searchResult = search(db, {
  term: 'if',
  properties: '*'
});

// output:

{
  elapsed: 99, // elapsed time is in microseconds
  hits: [
    {
      id: 'ckAOPGTA5qLXx0MgNr1Zy',
      quote: 'If you really look closely, most overnight successes took a long time.',
      author: 'Steve Jobs'
    },
    {
      id: 'fyl-_1veP78IO-wszP86Z',
      quote: 'If you are not willing to risk the usual, you will have to settle for the ordinary.',
      author: 'Jim Rohn'
    }
  ],
  count: 2
}
Lyra, developed and sponsored by NearForm.
Licensed under the Apache 2.0 license.