@filter-enginez/core

中文文档
0.2.0发布于 2026/11/01Apache-2.0TypeScriptES Module构建来源已验证

Faceted search and filtering engine for TypeScript: rules, and/or/not composition, filter groups, JSON config, undo/redo devtools, and Roaring Bitmap, R-tree, Bayesian suggestion and MinHash similarity acceleration. Runs in the browser, Node and Web Worke

原始使用文档
文档目录4 节
  1. Install
  2. Quick start
  3. Errors
  4. Documentation

@filter-enginez/core

The Filter EngineZ engine — rules, composition, devtools, internal store, action log, four named CS algorithms (Roaring Bitmaps, R-tree, Bayesian co-occurrence, MinHash + LSH). Isomorphic: runs in browsers, Node, Cloudflare Workers, Deno, edge runtimes.

Install

pnpm add @filter-enginez/core

Bitmap acceleration uses roaring-wasm, an optional peer dependency: core runs without it, and installing core does not install it. To enable bitmaps, install it alongside core and await initializeBitmapAcceleration() once at startup (see the quick start):

pnpm add roaring-wasm

Without it, initializeBitmapAcceleration() rejects with a FilterEngineModeError whose code is MODE_ACCELERATION_PEER_MISSING and whose message is the install command, and the engine keeps filtering through its predicate path with the same results. Nothing in the engine calls it for you, so an app that never does needs nothing more.

Sub-exports: @filter-enginez/core/keyboard/browser, @filter-enginez/core/similarity, @filter-enginez/core/storage/browser, @filter-enginez/core/suggestions.

similarity and suggestions are separate entry points deliberately: importing them is opt-in, so not importing them keeps their bytes out of your build.

Quick start

import { createFilterEngine, initializeBitmapAcceleration, InSetRule, RangeRule } from '@filter-enginez/core';
import { type Wine, wines } from '@filter-enginez/mock-data/wine';

// Await this once at startup, with roaring-wasm installed. It loads roaring-wasm, which an app that
// never calls it does not bundle. The Roaring-Bitmap path stays OFF until it resolves —
// silently, so an app whose WASM asset is still in flight keeps working rather than
// throwing. Skipping it costs roughly 40x on a 10k corpus and raises no warning.
await initializeBitmapAcceleration();

const engine = createFilterEngine<Wine>({ sourceData: wines });

engine.addRule('price', new RangeRule('priceUsd', { min: 20, max: 60 }));
engine.addRule('varietal', new InSetRule('varietal', ['Merlot', 'Syrah']));

engine.getResults(); // every wine passing BOTH rules
engine.getResultCount(); // cheaper when you only need the number

Rules AND together. To OR the rules of one facet, name them in a group (engine.addGroup({ id, filterIds })); for any other OR / NOT, compose with and / or / not and pass the result to engine.setExpression(...). The bitmap path serves conjunctions, so an expression or an 'or' group is evaluated per item instead — the results are the same.

Errors

Every error the engine raises is a FilterEngineError with a readonly, machine-readable code. Four subclasses name the family — FilterEngineConfigError (a config document, option object or binding is invalid), FilterEngineRuleError (a rule class or serialized rule is unusable; RuleRegistryError extends it), FilterEngineModeError (for example addRule() while an expression is set) and FilterEngineDestroyedError (any method after destroy()). A wrapped failure is the standard cause. The code unions are exported too (FilterEngineErrorCode and one per class), so a switch over error.code is checked for exhaustiveness.

import { createFilterEngine, type FilterEngineConfig, FilterEngineError } from '@filter-enginez/core';

declare const sharedConfig: FilterEngineConfig;

const engine = createFilterEngine({ sourceData: [] });

try {
  engine.loadConfig(sharedConfig);
} catch (error) {
  if (!(error instanceof FilterEngineError)) {
    throw error;
  }
  console.warn(`Ignoring a config the engine refused: ${error.code}`, error.cause);
}

The full code table, and when each is thrown, is in docs/architecture.md §2.5 of the engine repository.

Documentation

Consumer guides live in the engine repository under docs/guides/:

  • extending_rules.md — writing a custom FilterRule that survives serialization
  • json_config.md — declaring filters as data, and why the format is safe to accept from a tenant
  • acceleration_tuning.md — what the five acceleration toggles are worth, measured
  • worker_offload.md — running the engine in a Web Worker

Project home, with six live demos: https://filterenginez.com. Documentation site: https://docs.filterenginez.com.

Apache-2.0. See LICENSE.md and NOTICE.md, both included in this package.

版本与发布记录

@filter-enginez/core 共发布 7 个版本,首次发布于 2026/10/13;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/11/012 天前
0.1.12026/10/2311 天前
0.1.02026/10/2113 天前
0.0.32026/10/2014 天前
0.0.22026/10/1321 天前
0.0.12026/10/1321 天前

关于 @filter-enginez/core 的常见问题

@filter-enginez/core 是什么?

面向TypeScript的分面搜索和过滤引擎:规则,和/或/不组合,过滤器组,JSON配置,撤销/重做devtools,咆哮位图,r树,贝叶斯建议和MinHash相似度加速。在浏览器、Node和Web work中运行

如何安装 @filter-enginez/core?

在项目目录运行 npm install @filter-enginez/core,或使用 pnpm add / yarn add / bun add。

@filter-enginez/core 支持 TypeScript 吗?

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

@filter-enginez/core 支持 ESM 还是 CommonJS?

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

@filter-enginez/core 可以商用吗?

@filter-enginez/core 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@filter-enginez/core 还在维护吗?

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