ddys-search-index 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +8 -0
- package/LICENSE +21 -0
- package/README.en.md +73 -0
- package/README.md +87 -0
- package/bin/ddys-search-index.js +101 -0
- package/examples/cloudflare-worker/package.json +15 -0
- package/examples/cloudflare-worker/src/index.js +5 -0
- package/examples/cloudflare-worker/wrangler.jsonc +12 -0
- package/examples/github-actions/ddys-search-index.yml +22 -0
- package/examples/node-build/build-search-index.mjs +10 -0
- package/index.d.ts +133 -0
- package/package.json +72 -0
- package/src/client.js +128 -0
- package/src/config.js +212 -0
- package/src/index.js +7 -0
- package/src/indexer.js +182 -0
- package/src/normalize.js +203 -0
- package/src/renderers.js +40 -0
- package/src/runtime.js +79 -0
- package/src/utils.js +146 -0
- package/src/worker.js +89 -0
package/.env.example
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
DDYS_SEARCH_INDEX_API_BASE=https://ddys.io/api/v1
|
|
2
|
+
DDYS_SEARCH_INDEX_PUBLIC_BASE=https://ddys.io
|
|
3
|
+
DDYS_SEARCH_INDEX_SOURCES=latest,hot
|
|
4
|
+
DDYS_SEARCH_INDEX_MAX_ITEMS=50
|
|
5
|
+
DDYS_SEARCH_INDEX_MAX_PAGES=2
|
|
6
|
+
DDYS_SEARCH_INDEX_TTL_SECONDS=600
|
|
7
|
+
DDYS_SEARCH_INDEX_TIMEOUT_MS=10000
|
|
8
|
+
DDYS_SEARCH_INDEX_WORKER_CACHE=true
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ddysiodev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# ddys-search-index
|
|
2
|
+
|
|
3
|
+
Standalone search index generator for DDYS API data. It normalizes media items into frontend-ready `search-index.json` files with a compact inverted index, documents, facets, Node CLI, Cloudflare Workers routes, and GitHub Actions examples.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Fetches `latest`, `hot`, `calendar`, `search:keyword`, or custom API endpoint sources
|
|
8
|
+
- Builds indexes from local JSON files for offline and static workflows
|
|
9
|
+
- Emits `search-index.json`, `search-docs.json`, and `search-meta.json`
|
|
10
|
+
- Normalizes title, aliases, description, cast, directors, region, language, category, tags, and dates
|
|
11
|
+
- Includes token index, suggestions, and facets for category/year/region/language/source
|
|
12
|
+
- Worker routes for `/search-index.json`, `/search-docs.json`, `/search-meta.json`, `/search?q=...`, and `/health`
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install ddys-search-index
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or run it directly:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx ddys-search-index build --out-dir public/search
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## CLI
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
ddys-search-index build --source latest,hot --max-items 50 --out-dir public/search
|
|
30
|
+
ddys-search-index build --input data/items.json --out-dir public/search
|
|
31
|
+
ddys-search-index print --type index
|
|
32
|
+
ddys-search-index print --type meta
|
|
33
|
+
ddys-search-index diag
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Node API
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { generateSearchBundle, searchIndex } from 'ddys-search-index';
|
|
40
|
+
|
|
41
|
+
const bundle = await generateSearchBundle({
|
|
42
|
+
sources: ['latest', 'hot', 'search:sci-fi'],
|
|
43
|
+
maxItems: 40
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const result = searchIndex(bundle.index, 'sci-fi 2025', { limit: 10 });
|
|
47
|
+
console.log(result.items);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Cloudflare Workers
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import { createWorkerHandler } from 'ddys-search-index/worker';
|
|
54
|
+
|
|
55
|
+
export default {
|
|
56
|
+
fetch: createWorkerHandler({
|
|
57
|
+
sources: ['latest', 'hot'],
|
|
58
|
+
maxItems: 60
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Environment
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
DDYS_SEARCH_INDEX_API_BASE=https://ddys.io/api/v1
|
|
67
|
+
DDYS_SEARCH_INDEX_PUBLIC_BASE=https://ddys.io
|
|
68
|
+
DDYS_SEARCH_INDEX_SOURCES=latest,hot
|
|
69
|
+
DDYS_SEARCH_INDEX_MAX_ITEMS=50
|
|
70
|
+
DDYS_SEARCH_INDEX_MAX_PAGES=2
|
|
71
|
+
DDYS_SEARCH_INDEX_TTL_SECONDS=600
|
|
72
|
+
DDYS_SEARCH_INDEX_TIMEOUT_MS=10000
|
|
73
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# ddys-search-index
|
|
2
|
+
|
|
3
|
+
低端影视 API 的独立搜索索引生成器。它把 DDYS API 返回的影视条目标准化成前端可直接加载的 `search-index.json`,同时提供轻量倒排索引、文档列表、分面统计、Node CLI、Cloudflare Workers 路由和 GitHub Actions 静态生成示例。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 从 `latest`、`hot`、`calendar`、`search:关键词` 或自定义 API endpoint 拉取数据
|
|
8
|
+
- 从本地 JSON 文件生成索引,适合离线构建或接入已有采集结果
|
|
9
|
+
- 输出 `search-index.json`、`search-docs.json`、`search-meta.json`
|
|
10
|
+
- 内置标题、别名、简介、演员、导演、地区、语言、标签等字段归一化
|
|
11
|
+
- 生成倒排索引、建议词、分类/年份/地区/语言等分面统计
|
|
12
|
+
- Worker 支持 `/search-index.json`、`/search-docs.json`、`/search-meta.json`、`/search?q=...`、`/health`
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install ddys-search-index
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
也可以直接使用:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx ddys-search-index build --out-dir public/search
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## CLI
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
ddys-search-index build --source latest,hot --max-items 50 --out-dir public/search
|
|
30
|
+
ddys-search-index build --input data/items.json --out-dir public/search
|
|
31
|
+
ddys-search-index print --type index
|
|
32
|
+
ddys-search-index print --type meta
|
|
33
|
+
ddys-search-index diag
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
常用参数:
|
|
37
|
+
|
|
38
|
+
- `--api-base`:DDYS API 根地址
|
|
39
|
+
- `--public-base`:影视详情页根地址
|
|
40
|
+
- `--source`:数据源,支持 `latest`、`hot`、`calendar`、`search:关键词`、`endpoint:/path`
|
|
41
|
+
- `--input`:本地 JSON 文件,支持数组或常见 `{ data: [] }` / `{ items: [] }` 结构
|
|
42
|
+
- `--max-items`:每个源最多保留的条目数
|
|
43
|
+
- `--max-pages`:分页源最多抓取页数
|
|
44
|
+
- `--out-dir`:输出目录
|
|
45
|
+
|
|
46
|
+
## Node API
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { generateSearchBundle, searchIndex } from 'ddys-search-index';
|
|
50
|
+
|
|
51
|
+
const bundle = await generateSearchBundle({
|
|
52
|
+
sources: ['latest', 'hot', 'search:科幻'],
|
|
53
|
+
maxItems: 40
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const result = searchIndex(bundle.index, '科幻 2025', { limit: 10 });
|
|
57
|
+
console.log(result.items);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Cloudflare Workers
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { createWorkerHandler } from 'ddys-search-index/worker';
|
|
64
|
+
|
|
65
|
+
export default {
|
|
66
|
+
fetch: createWorkerHandler({
|
|
67
|
+
sources: ['latest', 'hot'],
|
|
68
|
+
maxItems: 60
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 环境变量
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
DDYS_SEARCH_INDEX_API_BASE=https://ddys.io/api/v1
|
|
77
|
+
DDYS_SEARCH_INDEX_PUBLIC_BASE=https://ddys.io
|
|
78
|
+
DDYS_SEARCH_INDEX_SOURCES=latest,hot
|
|
79
|
+
DDYS_SEARCH_INDEX_MAX_ITEMS=50
|
|
80
|
+
DDYS_SEARCH_INDEX_MAX_PAGES=2
|
|
81
|
+
DDYS_SEARCH_INDEX_TTL_SECONDS=600
|
|
82
|
+
DDYS_SEARCH_INDEX_TIMEOUT_MS=10000
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 输出
|
|
86
|
+
|
|
87
|
+
`search-index.json` 包含完整索引,可以直接放在静态站点或 Worker 缓存层后面;`search-docs.json` 只包含可展示文档;`search-meta.json` 包含统计、分面和建议词,适合前端初始化筛选器。
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import {
|
|
6
|
+
createConfig,
|
|
7
|
+
describeConfig,
|
|
8
|
+
generateSearchBundle,
|
|
9
|
+
readInputFile,
|
|
10
|
+
renderSearchDocs,
|
|
11
|
+
renderSearchIndex,
|
|
12
|
+
renderSearchMeta,
|
|
13
|
+
searchIndex,
|
|
14
|
+
writeSearchBundle
|
|
15
|
+
} from '../src/index.js';
|
|
16
|
+
import { VERSION } from '../src/config.js';
|
|
17
|
+
|
|
18
|
+
const args = parseArgs(process.argv.slice(2));
|
|
19
|
+
const command = args._[0] || 'build';
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (command === 'version' || args.version) {
|
|
23
|
+
console.log(VERSION);
|
|
24
|
+
} else if (command === 'diag') {
|
|
25
|
+
const config = createConfig(readCliConfig(args));
|
|
26
|
+
console.log(JSON.stringify({ ok: true, package: 'ddys-search-index', config: describeConfig(config) }, null, 2));
|
|
27
|
+
} else if (command === 'print') {
|
|
28
|
+
const bundle = await generateSearchBundle(await readCliConfigWithItems(args));
|
|
29
|
+
const type = String(args.type || 'index');
|
|
30
|
+
if (type === 'docs') process.stdout.write(renderSearchDocs(bundle.index));
|
|
31
|
+
else if (type === 'meta') process.stdout.write(renderSearchMeta(bundle.index));
|
|
32
|
+
else if (type === 'search') {
|
|
33
|
+
console.log(JSON.stringify(searchIndex(bundle.index, args.q || args.query || ''), null, 2));
|
|
34
|
+
} else {
|
|
35
|
+
process.stdout.write(renderSearchIndex(bundle.index));
|
|
36
|
+
}
|
|
37
|
+
} else if (command === 'build') {
|
|
38
|
+
const outDir = path.resolve(String(args['out-dir'] || args.outDir || 'public/search'));
|
|
39
|
+
const bundle = await generateSearchBundle(await readCliConfigWithItems(args));
|
|
40
|
+
await mkdir(outDir, { recursive: true });
|
|
41
|
+
const files = await writeSearchBundle(bundle, outDir);
|
|
42
|
+
if (args.manifest) {
|
|
43
|
+
await writeFile(path.join(outDir, 'manifest.json'), JSON.stringify({
|
|
44
|
+
package: 'ddys-search-index',
|
|
45
|
+
version: VERSION,
|
|
46
|
+
generatedAt: bundle.index.generatedAt,
|
|
47
|
+
files: bundle.files.map((file) => file.path),
|
|
48
|
+
stats: bundle.index.stats
|
|
49
|
+
}, null, 2), 'utf8');
|
|
50
|
+
}
|
|
51
|
+
console.log(JSON.stringify({ ok: true, documents: bundle.index.stats.documents, tokens: bundle.index.stats.tokens, files }, null, 2));
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error(`Unknown command: ${command}`);
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(JSON.stringify({ ok: false, message: error.message }, null, 2));
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function readCliConfigWithItems(args) {
|
|
61
|
+
const config = readCliConfig(args);
|
|
62
|
+
const input = args.input || args['input-file'] || args.inputFile;
|
|
63
|
+
if (input) config.items = await readInputFile(path.resolve(String(input)));
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function readCliConfig(args) {
|
|
68
|
+
const out = {};
|
|
69
|
+
if (args['api-base'] || args.apiBase) out.apiBase = args['api-base'] || args.apiBase;
|
|
70
|
+
if (args['public-base'] || args.publicBase) out.publicBase = args['public-base'] || args.publicBase;
|
|
71
|
+
if (args.source) out.sources = args.source;
|
|
72
|
+
if (args.sources) out.sources = args.sources;
|
|
73
|
+
if (args['max-items'] || args.maxItems) out.maxItems = args['max-items'] || args.maxItems;
|
|
74
|
+
if (args['max-pages'] || args.maxPages) out.maxPages = args['max-pages'] || args.maxPages;
|
|
75
|
+
if (args['ttl-seconds'] || args.ttlSeconds) out.ttlSeconds = args['ttl-seconds'] || args.ttlSeconds;
|
|
76
|
+
if (args['timeout-ms'] || args.timeoutMs) out.requestTimeoutMs = args['timeout-ms'] || args.timeoutMs;
|
|
77
|
+
if (args.fields) out.fields = args.fields;
|
|
78
|
+
if (args.facets) out.facets = args.facets;
|
|
79
|
+
if (args['include-raw'] || args.includeRaw) out.includeRaw = args['include-raw'] || args.includeRaw;
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parseArgs(argv) {
|
|
84
|
+
const out = { _: [] };
|
|
85
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
86
|
+
const arg = argv[index];
|
|
87
|
+
if (!arg.startsWith('--')) {
|
|
88
|
+
out._.push(arg);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const key = arg.slice(2);
|
|
92
|
+
const next = argv[index + 1];
|
|
93
|
+
if (!next || next.startsWith('--')) {
|
|
94
|
+
out[key] = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
out[key] = next;
|
|
98
|
+
index += 1;
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ddys-search-index-worker-example",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "wrangler dev",
|
|
7
|
+
"deploy": "wrangler deploy"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"ddys-search-index": "^0.1.0"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"wrangler": "^4.0.0"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ddys-search-index",
|
|
3
|
+
"main": "src/index.js",
|
|
4
|
+
"compatibility_date": "2026-07-11",
|
|
5
|
+
"vars": {
|
|
6
|
+
"DDYS_SEARCH_INDEX_API_BASE": "https://ddys.io/api/v1",
|
|
7
|
+
"DDYS_SEARCH_INDEX_PUBLIC_BASE": "https://ddys.io",
|
|
8
|
+
"DDYS_SEARCH_INDEX_SOURCES": "latest,hot",
|
|
9
|
+
"DDYS_SEARCH_INDEX_MAX_ITEMS": "50",
|
|
10
|
+
"DDYS_SEARCH_INDEX_MAX_PAGES": "2"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Build DDYS search index
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
schedule:
|
|
5
|
+
- cron: "*/30 * * * *"
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 22
|
|
18
|
+
- run: npx ddys-search-index build --source latest,hot --out-dir public/search --manifest
|
|
19
|
+
- uses: peaceiris/actions-gh-pages@v4
|
|
20
|
+
with:
|
|
21
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
22
|
+
publish_dir: ./public
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { generateSearchBundle, writeSearchBundle } from 'ddys-search-index';
|
|
2
|
+
|
|
3
|
+
const bundle = await generateSearchBundle({
|
|
4
|
+
sources: ['latest', 'hot'],
|
|
5
|
+
maxItems: 50,
|
|
6
|
+
maxPages: 2
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const files = await writeSearchBundle(bundle, new URL('./public/search', import.meta.url).pathname);
|
|
10
|
+
console.log(JSON.stringify({ ok: true, documents: bundle.index.stats.documents, files }, null, 2));
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export interface DdysSearchSource {
|
|
2
|
+
kind: 'latest' | 'hot' | 'calendar' | 'search' | 'endpoint' | string;
|
|
3
|
+
label: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
query?: Record<string, unknown>;
|
|
7
|
+
value?: string;
|
|
8
|
+
limit: number;
|
|
9
|
+
maxPages: number;
|
|
10
|
+
paginated: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DdysSearchConfig {
|
|
14
|
+
version: string;
|
|
15
|
+
apiBase: string;
|
|
16
|
+
publicBase: string;
|
|
17
|
+
userAgent: string;
|
|
18
|
+
source: DdysSearchSource;
|
|
19
|
+
sources: DdysSearchSource[];
|
|
20
|
+
maxItems: number;
|
|
21
|
+
maxPages: number;
|
|
22
|
+
ttlSeconds: number;
|
|
23
|
+
requestTimeoutMs: number;
|
|
24
|
+
minTokenLength: number;
|
|
25
|
+
includeRaw: boolean;
|
|
26
|
+
workerCache: boolean;
|
|
27
|
+
fields: string[];
|
|
28
|
+
facets: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SearchDocument {
|
|
32
|
+
id: string;
|
|
33
|
+
title: string;
|
|
34
|
+
aliases?: string[];
|
|
35
|
+
description?: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
poster?: string;
|
|
38
|
+
year?: number;
|
|
39
|
+
date?: string;
|
|
40
|
+
category?: string[];
|
|
41
|
+
tags?: string[];
|
|
42
|
+
actors?: string[];
|
|
43
|
+
directors?: string[];
|
|
44
|
+
region?: string[];
|
|
45
|
+
language?: string[];
|
|
46
|
+
score?: number;
|
|
47
|
+
status?: string;
|
|
48
|
+
source?: string;
|
|
49
|
+
text?: string;
|
|
50
|
+
raw?: unknown;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface SearchFacetItem {
|
|
54
|
+
value: string;
|
|
55
|
+
count: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface SearchIndex {
|
|
59
|
+
version: string;
|
|
60
|
+
generatedAt: string;
|
|
61
|
+
checksum: string;
|
|
62
|
+
config: {
|
|
63
|
+
apiBase: string;
|
|
64
|
+
publicBase: string;
|
|
65
|
+
sources: Array<Pick<DdysSearchSource, 'kind' | 'label' | 'slug' | 'endpoint' | 'query'>>;
|
|
66
|
+
fields: string[];
|
|
67
|
+
facets: string[];
|
|
68
|
+
minTokenLength: number;
|
|
69
|
+
};
|
|
70
|
+
stats: {
|
|
71
|
+
documents: number;
|
|
72
|
+
tokens: number;
|
|
73
|
+
suggestions: number;
|
|
74
|
+
};
|
|
75
|
+
documents: SearchDocument[];
|
|
76
|
+
index: Record<string, Array<[string, number]>>;
|
|
77
|
+
documentTokens: Record<string, string[]>;
|
|
78
|
+
facets: Record<string, SearchFacetItem[]>;
|
|
79
|
+
suggestions: string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface SearchResultItem {
|
|
83
|
+
score: number;
|
|
84
|
+
document: SearchDocument;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface SearchResult {
|
|
88
|
+
query: string;
|
|
89
|
+
tokens: string[];
|
|
90
|
+
total: number;
|
|
91
|
+
items: SearchResultItem[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface SearchBundleFile {
|
|
95
|
+
path: string;
|
|
96
|
+
contentType: string;
|
|
97
|
+
contents: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface SearchBundle {
|
|
101
|
+
ok: true;
|
|
102
|
+
config: ReturnType<typeof describeConfig>;
|
|
103
|
+
sources: Array<{ source: string; urls: string[]; items: number }>;
|
|
104
|
+
index: SearchIndex;
|
|
105
|
+
files: SearchBundleFile[];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function createConfig(input?: Partial<DdysSearchConfig> | Record<string, unknown>, env?: Record<string, string | undefined>): DdysSearchConfig;
|
|
109
|
+
export function loadConfigFromEnv(env?: Record<string, string | undefined>): DdysSearchConfig;
|
|
110
|
+
export function describeConfig(config: DdysSearchConfig): Record<string, unknown>;
|
|
111
|
+
export function buildApiUrl(pathname: string, query: Record<string, unknown>, config: DdysSearchConfig): string;
|
|
112
|
+
export function extractItems(payload: unknown): unknown[];
|
|
113
|
+
export function fetchJson(pathname: string, query: Record<string, unknown>, config: DdysSearchConfig, runtime?: { fetch?: typeof fetch }): Promise<{ url: string; payload: unknown }>;
|
|
114
|
+
export function fetchSearchSource(source: DdysSearchSource, config: DdysSearchConfig, runtime?: { fetch?: typeof fetch }): Promise<{ source: DdysSearchSource; urls: string[]; payloads: unknown[]; items: unknown[] }>;
|
|
115
|
+
export function fetchSearchSources(sources: DdysSearchSource[], config: DdysSearchConfig, runtime?: { fetch?: typeof fetch }): Promise<Array<{ source: DdysSearchSource; urls: string[]; payloads: unknown[]; items: unknown[] }>>;
|
|
116
|
+
export function normalizeDocument(item: unknown, source: Partial<DdysSearchSource> | null, config: DdysSearchConfig): SearchDocument | null;
|
|
117
|
+
export function normalizeRecords(records: unknown[], config: DdysSearchConfig): SearchDocument[];
|
|
118
|
+
export function buildSearchIndex(records: unknown[], config: DdysSearchConfig, runtime?: { now?: () => number }): SearchIndex;
|
|
119
|
+
export function searchIndex(searchIndexValue: SearchIndex, query: string, options?: { limit?: number; filters?: Record<string, unknown>; minTokenLength?: number }): SearchResult;
|
|
120
|
+
export function tokenize(value: string, options?: { minTokenLength?: number }): string[];
|
|
121
|
+
export function buildFacets(documents: SearchDocument[], facetNames: string[]): Record<string, SearchFacetItem[]>;
|
|
122
|
+
export function renderSearchIndex(searchIndex: SearchIndex, options?: { pretty?: boolean }): string;
|
|
123
|
+
export function renderSearchDocs(searchIndex: SearchIndex, options?: { pretty?: boolean }): string;
|
|
124
|
+
export function renderSearchMeta(searchIndex: SearchIndex, options?: { pretty?: boolean }): string;
|
|
125
|
+
export function buildSearchFiles(searchIndex: SearchIndex, options?: { pretty?: boolean }): SearchBundleFile[];
|
|
126
|
+
export function generateSearchIndex(input?: Record<string, unknown>, runtime?: { fetch?: typeof fetch; now?: () => number; env?: Record<string, string | undefined> }): Promise<Omit<SearchBundle, 'files'>>;
|
|
127
|
+
export function generateSearchBundle(input?: Record<string, unknown>, runtime?: { fetch?: typeof fetch; now?: () => number; env?: Record<string, string | undefined> }): Promise<SearchBundle>;
|
|
128
|
+
export function writeSearchBundle(bundle: SearchBundle, outDir: string): Promise<string[]>;
|
|
129
|
+
export function readInputFile(filePath: string): Promise<unknown[]>;
|
|
130
|
+
export function buildOutputHeaders(type: string, searchIndexValue: SearchIndex, config: DdysSearchConfig): Record<string, string>;
|
|
131
|
+
export function createWorkerHandler(input?: Record<string, unknown>): (request: Request, env?: Record<string, string | undefined>, ctx?: unknown) => Promise<Response>;
|
|
132
|
+
export function handleWorkerRequest(request: Request, runtime?: Record<string, unknown>): Promise<Response>;
|
|
133
|
+
export function routeForPath(pathname: string): 'health' | 'search' | 'index' | 'docs' | 'meta' | 'not-found';
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ddys-search-index",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Search index generator for DDYS API data with Node CLI and Cloudflare Workers support.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/ddysiodev/ddys-search-index",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ddysiodev/ddys-search-index.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ddysiodev/ddys-search-index/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ddys",
|
|
17
|
+
"search",
|
|
18
|
+
"search-index",
|
|
19
|
+
"inverted-index",
|
|
20
|
+
"cloudflare-workers",
|
|
21
|
+
"github-actions",
|
|
22
|
+
"movie",
|
|
23
|
+
"api"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"ddys-search-index": "./bin/ddys-search-index.js"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"import": "./src/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./config": {
|
|
34
|
+
"types": "./index.d.ts",
|
|
35
|
+
"import": "./src/config.js"
|
|
36
|
+
},
|
|
37
|
+
"./client": {
|
|
38
|
+
"types": "./index.d.ts",
|
|
39
|
+
"import": "./src/client.js"
|
|
40
|
+
},
|
|
41
|
+
"./indexer": {
|
|
42
|
+
"types": "./index.d.ts",
|
|
43
|
+
"import": "./src/indexer.js"
|
|
44
|
+
},
|
|
45
|
+
"./worker": {
|
|
46
|
+
"types": "./index.d.ts",
|
|
47
|
+
"import": "./src/worker.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"main": "./src/index.js",
|
|
51
|
+
"types": "./index.d.ts",
|
|
52
|
+
"files": [
|
|
53
|
+
"bin",
|
|
54
|
+
"src",
|
|
55
|
+
"examples",
|
|
56
|
+
"index.d.ts",
|
|
57
|
+
"README.md",
|
|
58
|
+
"README.en.md",
|
|
59
|
+
"LICENSE",
|
|
60
|
+
".env.example"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"check": "node tools/check.mjs",
|
|
64
|
+
"test": "node tools/check.mjs && node --test tests/*.test.mjs"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=20.0.0"
|
|
71
|
+
}
|
|
72
|
+
}
|