# ndx-index

> Indexing functions for a lightweight full-text searching and indexing library ndx.

Latest version **1.0.0-beta.0** (published 2019-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install ndx-index
pnpm add ndx-index
yarn add ndx-index
bun add ndx-index
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.0 |
| Published | 2019-01-10 |
| First published | 2019-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 57.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Boris Kaul |
| Maintainers | localvoid |
| Keywords | ndx |

## Links

- npm: https://www.npmjs.com/package/ndx-index
- Repository: https://github.com/ndx-search/ndx-index
- Issues: https://github.com/localvoid/ndx-search/ndx-index/issues
- npm.io page: https://npm.io/package/ndx-index

## Dependencies (1)

- [ndx](https://npm.io/package/ndx.md) ^1.0.0-beta.1

## Recent versions

- 1.0.0-beta.0 (latest) — 2019-01-10

## README

# [ndx](https://github.com/ndx-search/ndx-index) &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ndx-search/ndx-index/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/ndx-index.svg)](https://www.npmjs.com/package/ndx-index) [![codecov](https://codecov.io/gh/ndx-search/ndx-index/branch/master/graph/badge.svg)](https://codecov.io/gh/ndx-search/ndx-index) [![CircleCI Status](https://circleci.com/gh/ndx-search/ndx-index.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/ndx-search/ndx-index) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/ndx-search/ndx-index)

Indexing functions for a lightweight javascript (TypeScript) full-text indexing and searching library
[ndx](https://github.com/ndx-search/ndx-index).

## Documentation

### Add Document to the Index

```ts
function addDocumentToIndex<I, D>(
  index: Index<I>,
  fieldAccessors: Array<(doc: D) => string>,
  tokenizer: (s: string) => string[],
  filter: (s: string) => string,
  id: I,
  document: D,
): void;
```

`addDocumentToIndex()` adds document to an `index`.

#### Example

```ts
import { createIndex } from "ndx";
import { addDocumentToIndex } from "ndx-index";

const index = createIndex(2);
const tokenizer = (s: string) => s.split(" ");
const filter = (s: string) => s;
function add(d) {
  addDocumentToIndex(
    index,
    [
      (d) => d.title,
      (d) => d.text,
    ],
    t,
    filter,
    d.id,
    d,
  );
}

const doc = {
  id: 1,
  title: "Title"
  text: "text",
};

add(doc);
```

### Remove Document From the Index

```ts
function removeDocumentFromIndex<I>(
  index: Index<I>,
  removed: Set<I>, id: I,
): void;
```

`removeDocumentFromIndex()` adds document to a set of `removed` documents. This function doesn't automatically cleans up
inverted index, but all items from the `removed` set will be ignored. `vacuumIndex()` function cleans up inverted index.

### Clean Up Index

```ts
function vacuumIndex<I>(
  index: Index<I>,
  removed: Set<I>,
): void;
```

`vacuumIndex()` cleans up inverted index and resets set of `removed` documents.

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