# @nearform/lyra

> Fast, in-memory, typo-tolerant, full-text search engine

Latest version **0.1.1** (published 2022-08-23) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @nearform/lyra
pnpm add @nearform/lyra
yarn add @nearform/lyra
bun add @nearform/lyra
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2022-08-23 |
| First published | 2022-06-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Michele Riva |
| Maintainers | micheleriva, donal.moynihan, rafaelgss, jimmymintzer, shogun_panda, simoneb, irelandm, eamonn.frisby |

## Links

- npm: https://www.npmjs.com/package/@nearform/lyra
- Issues: https://github.com/nearform/lyra
- npm.io page: https://npm.io/package/@nearform/lyra

## Recent versions

- 0.1.1 (latest) — 2022-08-23
- 0.0.5 — 2022-08-21
- 0.0.4 — 2022-08-09
- 0.0.3 — 2022-08-05
- 0.0.2 — 2022-08-04
- 0.0.1 — 2022-08-02
- 0.0.1-beta-19 — 2022-08-02
- 0.0.1-beta-18 — 2022-08-01
- 0.0.1-beta-17 — 2022-07-30
- 0.0.1-beta-16 — 2022-07-30
- 0.0.1-beta-15 — 2022-07-29
- 0.0.1-beta-14 — 2022-07-25
- 0.0.1-beta-13 — 2022-07-19
- 0.0.1-beta-12 — 2022-07-18
- 0.0.1-beta-11 — 2022-07-18
- … 8 more at https://npm.io/package/@nearform/lyra/versions

## README

![Lyra](https://raw.githubusercontent.com/nearform/lyra/main/misc/lyra-logo.png?token=GHSAT0AAAAAABTJOQRPLKOPT2AXUFO6TAOGYUQR75A)

[![Tests](https://github.com/nearform/lyra/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/nearform/lyra/actions/workflows/tests.yml)

Try the [live demo](https://nearform.github.io/lyra/demo)

# MOVED TO @LYRASEARCH/LYRA

# Installation

You can install Lyra using `npm`, `yarn`, `pnpm`:

```sh
npm i @lyrasearch/lyra
```

```sh
yarn add @lyrasearch/lyra
```

```sh
pnpm add @lyrasearch/lyra
```

# Usage

Lyra is quite simple to use. The first thing to do is to create a new database
instance and set an indexing schema:

```js
import { create, insert, search } from "@lyrasearch/lyra";

const db = create({
  schema: {
    author: "string",
    quote: "string",
  },
});
```

Lyra will only index string properties, but will allow you to set and store
additional data if needed.

Once the db instance is created, you can start adding some documents:

```js
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",
});
```

After the data has been inserted, you can finally start to query the database.

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

In the case above, you will be searching for all the documents containing the
word `if`, looking up in every schema property (AKA index):

```js
{
  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
}
```

You can also restrict the lookup to a specific property:

```js
const searchResult = search(db, {
  term: "Michael",
  properties: ["author"],
});
```

Result:

```js
{
  elapsed: 111,
  hits: [
    {
      id: 'L1tpqQxc0c2djrSN2a6TJ',
      quote: "You miss 100% of the shots you don't take",
      author: 'Wayne Gretzky - Michael Scott'
    }
  ],
  count: 1
}
```

If needed, you can also delete a given document by using the `delete` method:

```js
delete (db, "L1tpqQxc0c2djrSN2a6TJ");
```

# License

Lyra is licensed under the [Apache 2.0](/LICENSE.md) license.

---
_Source: https://npm.io/package/@nearform/lyra · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
