ndx-index
v1.0.0-beta.0
Published
Indexing functions for a lightweight full-text searching and indexing library ndx.
Downloads
3
Readme
ndx ·
Indexing functions for a lightweight javascript (TypeScript) full-text indexing and searching library ndx.
Documentation
Add Document to the Index
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
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
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
function vacuumIndex<I>(
index: Index<I>,
removed: Set<I>,
): void;
vacuumIndex()
cleans up inverted index and resets set of removed
documents.