@backloghq/termlog

中文文档
0.2.0发布于 2026/05/30MITTypeScriptES Module零依赖近 30 天下载 2002

Log-structured full-text search index — segment-based posting lists with LSM compaction, BM25 ranking, zero native dependencies.

原始使用文档
文档目录10 节
  1. Install
  2. Usage
  3. Why
  4. Architecture
  5. S3 backend
  6. Options
  7. Errors
  8. Stats
  9. Multi-writer / S3 safety
  10. License

@backloghq/termlog

Log-structured full-text search index — segment-based posting lists with LSM compaction, BM25 ranking, zero native dependencies.

Install

npm install @backloghq/termlog

Usage

import { TermLog } from "@backloghq/termlog";

const index = await TermLog.open({ dir: "./my-index" });

await index.add("doc-1", "the quick brown fox");
await index.add("doc-2", "the lazy dog");
await index.flush();

const results = await index.search("fox", { limit: 10 });
// [{ docId: "doc-1", score: 0.655... }]  (BM25 — exact value depends on corpus)

await index.remove("doc-1");
await index.close();

Why

Existing FTS engines (Lucene, Tantivy) require native deps or a JVM. Most pure-JS alternatives serialize the index to a single in-memory blob — fine for small corpora, but they hit per-file size cliffs in the tens of thousands of documents. Termlog uses immutable on-disk segments with LSM compaction so the corpus scales without those ceilings.

Architecture

  • Posting lists — term → [docId, tf], compressed with VByte / delta encoding. (Positions reserved for a future release.)
  • Term dictionary — sorted on disk; binary search for lookup.
  • Segments — self-contained immutable files (term dict + postings). New writes create a new segment. Compaction merges N segments into 1.
  • Query execution — boolean (AND/OR) via posting iterators (zigzag merge for AND, union scan for OR), BM25 scoring on top.
  • Storage — abstracted via StorageBackend; local FS by default, S3 via @backloghq/termlog-s3.

S3 backend

S3 support is provided by the companion package @backloghq/termlog-s3:

npm install @backloghq/termlog @backloghq/termlog-s3
import { TermLog } from "@backloghq/termlog";
import { S3Backend } from "@backloghq/termlog-s3";
import { S3Client } from "@aws-sdk/client-s3";

const index = await TermLog.open({
  dir: "my-index",
  backend: new S3Backend({
    client: new S3Client({ region: "us-east-1" }),
    bucket: "my-bucket",
    prefix: "my-index/",
  }),
});

See the termlog-s3 README for IAM permissions, lifecycle rules, and MinIO/LocalStack usage.

Options

OptionDefaultDescription
fanout4Same-tier segment count that triggers a merge (size-tiered LSM)
flushThreshold1000Docs in write buffer before auto-flush
k11.2BM25 term-saturation parameter
b0.75BM25 length-normalization parameter

Errors

ClassWhen thrown
ManifestCorruptionErrormanifest.json contains invalid JSON
ManifestVersionErrormanifest version is outside the supported range
SegmentCorruptionErrorCRC32 mismatch or missing segment file (.region tells you which)
MappingCorruptionErrordocids.snap or docids.log is corrupt
TokenizerMismatchErrorreopening an index with a different tokenizer config
IndexLockedErroranother process holds the advisory .lock file
WriteStreamErrorbase class for streaming write failures (S3 multipart, etc.)

Stats

MethodReturnsDescription
docCount()numberDocuments indexed across all flushed segments
segmentCount()numberNumber of active on-disk segments
estimatedBytes()numberApproximate in-memory footprint (postings buffers + sidecar arrays + Maps); lower-bound estimate for memory-budget callers

Multi-writer / S3 safety

Termlog is single-writer per index directory. On local FS an advisory .lock file prevents concurrent opens in the same process group. On S3 (or any shared storage) there is no distributed lock — you must ensure at most one writer per index path.

License

MIT

版本与发布记录

@backloghq/termlog 共发布 4 个版本,首次发布于 2026/05/05;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.2.0latest2026/05/305 个月前
0.1.22026/05/056 个月前
0.1.12026/05/056 个月前
0.1.02026/05/056 个月前

关于 @backloghq/termlog 的常见问题

@backloghq/termlog 是什么?

Log-structured full-text search index — segment-based posting lists with LSM compaction, BM25 ranking, zero native dependencies.

如何安装 @backloghq/termlog?

在项目目录运行 npm install @backloghq/termlog,或使用 pnpm add / yarn add / bun add。

@backloghq/termlog 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@backloghq/termlog 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@backloghq/termlog 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@backloghq/termlog 可以商用吗?

@backloghq/termlog 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@backloghq/termlog 的下载量有多少?

根据 npm 官方下载统计,@backloghq/termlog 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,002 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@backloghq/termlog 还在维护吗?

最新版本 0.2.0 发布于 2026/05/30(5 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/05/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。