TextSearchOptions
KIT · interface · Type contract
App supplies fields, tokenizer and its own schema/tokenizer revision.
Import
ts
import type { TextSearchOptions } from '@jangts/agent-core/kits/search';1
js
/** @typedef {import('@jangts/agent-core/kits/search').TextSearchOptions} TextSearchOptions */1
Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits, @jangts/agent-core/kits/search.
Definition
ts
interface TextSearchOptions<Document>1
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Document | { id: string } | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
indexRevision | string | Required | Read-only. App-owned revision of the field/tokenizer configuration; a change invalidates snapshots. |
fields | readonly (keyof Document & string)[] | Required | Read-only. Fields that are indexed and searchable. |
storedFields | readonly (keyof Document & string)[] | Required | Read-only. Fields returned in a hit; the indexed body is not implicitly returned. |
tokenize | ((text: string, fieldName?: string) => string[]) | undefined | Optional | Read-only. Tokenizer override; defaults to MiniSearch's default tokenizer. |
boost | Readonly<Partial<Record<keyof Document & string, number>>> | undefined | Optional | Read-only. Per-field relevance multiplier; omitted fields keep the default weight. |
combineWith | "AND" | "OR" | undefined | Optional | Read-only. How multiple query terms combine; defaults to the engine default (OR). |
Examples
- TextSearch: App-side full-text index: Build a local index over declared fields; every query must supply an application filter.
First index two interface documents
Beginner · Node.js
ts
import { TextSearch } from '@jangts/agent-core/kits/search';
type Document = { id: string; title: string; body: string };
const index = new TextSearch<Document>({ indexRevision: 'manual-v1', fields: ['title', 'body'], storedFields: ['title'] });
index.upsert({ id: 'workflow', title: 'Workflow', body: 'Define reusable agent nodes.' });
index.upsert({ id: 'model', title: 'Model', body: 'Bind a model provider.' });
console.log(index.search({ query: 'agent', limit: 5, filter: () => true }));1
2
3
4
5
6
2
3
4
5
6
js
import { TextSearch } from '@jangts/agent-core/kits/search';
const index = new TextSearch({ indexRevision: 'manual-v1', fields: ['title', 'body'], storedFields: ['title'] });
index.upsert({ id: 'workflow', title: 'Workflow', body: 'Define reusable agent nodes.' });
index.upsert({ id: 'model', title: 'Model', body: 'Bind a model provider.' });
console.log(index.search({ query: 'agent', limit: 5, filter: () => true }));1
2
3
4
5
2
3
4
5
Add access filtering, weighting, and a snapshot to the same search
Configuration · Node.js
Metadata allowed for filtering must be registered as storedFields; field filtering must rely on a trusted App identity and must not trust an identity the model claims.
ts
import { TextSearch } from '@jangts/agent-core/kits/search';
type Document = { id: string; title: string; body: string; audience: string };
const options = { indexRevision: 'manual-v2', fields: ['title', 'body'] as const, storedFields: ['title', 'audience'] as const, boost: { title: 3 }, combineWith: 'AND' as const };
const index = new TextSearch<Document>(options);
index.upsert({ id: 'workflow', title: 'Agent Workflow', body: 'Define reusable nodes.', audience: 'public' });
index.upsert({ id: 'private', title: 'Agent internals', body: 'Internal notes.', audience: 'owner' });
const restored = TextSearch.restore<Document>(options, index.snapshot());
console.log(restored.search({ query: 'agent', limit: 5, filter: document => document.audience === 'public' }));
await restored.remove('workflow');1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { TextSearch } from '@jangts/agent-core/kits/search';
const options = { indexRevision: 'manual-v2', fields: ['title', 'body'], storedFields: ['title', 'audience'], boost: { title: 3 }, combineWith: 'AND' };
const index = new TextSearch(options);
index.upsert({ id: 'workflow', title: 'Agent Workflow', body: 'Define reusable nodes.', audience: 'public' });
index.upsert({ id: 'private', title: 'Agent internals', body: 'Internal notes.', audience: 'owner' });
const restored = TextSearch.restore(options, index.snapshot());
console.log(restored.search({ query: 'agent', limit: 5, filter: document => document.audience === 'public' }));
await restored.remove('workflow');1
2
3
4
5
6
7
8
2
3
4
5
6
7
8