@cloud411716/fancy-webnovel 4.30.38 → 4.30.39
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.
|
@@ -158,6 +158,13 @@ function validateRecord(raw, line, seenIds) {
|
|
|
158
158
|
tags: raw.tags.map((item) => item.trim()),
|
|
159
159
|
...(raw.subject ? { subject: raw.subject.trim() } : {}),
|
|
160
160
|
...(raw.derivation ? { derivation: raw.derivation.trim() } : {}),
|
|
161
|
+
search_text: [
|
|
162
|
+
raw.kind, raw.name,
|
|
163
|
+
raw.subkind, raw.world_id, raw.group_id,
|
|
164
|
+
raw.subject, raw.derivation, raw.note,
|
|
165
|
+
...(Array.isArray(raw.tags) ? raw.tags : []),
|
|
166
|
+
...MATERIAL_FACET_FIELDS.flatMap((facet) => (Array.isArray(raw[facet]) ? raw[facet] : [])),
|
|
167
|
+
].filter((value) => typeof value === 'string' && value.trim()).join(' '),
|
|
161
168
|
...Object.fromEntries(MATERIAL_FACET_FIELDS.map((facet) => [
|
|
162
169
|
facet,
|
|
163
170
|
(raw[facet] || []).map((item) => item.trim()),
|
|
@@ -29,6 +29,7 @@ DEFINE FIELD OVERWRITE name ON material TYPE string;
|
|
|
29
29
|
DEFINE FIELD OVERWRITE tags ON material TYPE array<string> DEFAULT [];
|
|
30
30
|
DEFINE FIELD OVERWRITE subject ON material TYPE option<string>;
|
|
31
31
|
DEFINE FIELD OVERWRITE derivation ON material TYPE option<string>;
|
|
32
|
+
DEFINE FIELD OVERWRITE search_text ON material TYPE option<string>;
|
|
32
33
|
DEFINE FIELD OVERWRITE genres ON material TYPE array<string> DEFAULT [];
|
|
33
34
|
DEFINE FIELD OVERWRITE tropes ON material TYPE option<array<string>>;
|
|
34
35
|
DEFINE FIELD OVERWRITE narrative ON material TYPE option<array<string>>;
|
|
@@ -75,6 +76,7 @@ DEFINE INDEX IF NOT EXISTS material_name_search
|
|
|
75
76
|
SEARCH ANALYZER material_zh
|
|
76
77
|
BM25(1.2, 0.75);
|
|
77
78
|
|
|
79
|
+
|
|
78
80
|
-- ---------------------------------------------------------------------------
|
|
79
81
|
-- 抖音账号(v12)
|
|
80
82
|
--
|
package/lib/material-db.js
CHANGED
|
@@ -17,7 +17,7 @@ import { readSecrets, readWorkspace } from './workspace.js';
|
|
|
17
17
|
import { rpcUrl, startServer } from './surreal-server.js';
|
|
18
18
|
|
|
19
19
|
export const MATERIAL_DATABASE = 'material_library';
|
|
20
|
-
export const MATERIAL_SCHEMA_VERSION =
|
|
20
|
+
export const MATERIAL_SCHEMA_VERSION = 16;
|
|
21
21
|
|
|
22
22
|
const SCHEMA_FILE = fileURLToPath(new URL('../docs/material-library/schema.surql', import.meta.url));
|
|
23
23
|
|
|
@@ -61,7 +61,7 @@ export async function connectMaterial(root) {
|
|
|
61
61
|
/**
|
|
62
62
|
* Ensure the material database and its schema exist. Idempotent.
|
|
63
63
|
*
|
|
64
|
-
* Schema v15 adds material.derivation; v14 changes the builtin kind catalog and adds material.world_id / rank_order; v13 adds the douyin_style table; v12 adds the douyin_account table; v11 adds the multi-layer material facets (`subject`, `tropes`, `narrative`, `traits`, `roles`, `relations`, `moods`, `settings`) and keeps the v10 douyin task tables / v9 subkind / v8 note assertion / v7 group_id / 58-kind catalog. Before applying the
|
|
64
|
+
* Schema v16 adds material.search_text and its full-text index; v15 adds material.derivation; v14 changes the builtin kind catalog and adds material.world_id / rank_order; v13 adds the douyin_style table; v12 adds the douyin_account table; v11 adds the multi-layer material facets (`subject`, `tropes`, `narrative`, `traits`, `roles`, `relations`, `moods`, `settings`) and keeps the v10 douyin task tables / v9 subkind / v8 note assertion / v7 group_id / 58-kind catalog. Before applying the
|
|
65
65
|
* new ASSERT, rows belonging to retired kinds are removed; otherwise SurrealDB
|
|
66
66
|
* refuses to overwrite the field because existing records no longer conform.
|
|
67
67
|
*
|
|
@@ -99,10 +99,33 @@ export async function ensureMaterialDatabase(root) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
await db.query(materialSchemaText());
|
|
102
|
+
// Backfill the internal full-text document for rows created before v16.
|
|
103
|
+
const missingSearch = await db.query("SELECT count() AS n FROM material WHERE search_text = NONE GROUP ALL;");
|
|
104
|
+
const missingSearchRow = Array.isArray(missingSearch) && Array.isArray(missingSearch[0]) ? missingSearch[0][0] : null;
|
|
105
|
+
if (missingSearchRow && Number(missingSearchRow.n) > 0) {
|
|
106
|
+
await db.query(`UPDATE material SET search_text = array::join(array::flatten([
|
|
107
|
+
kind, name,
|
|
108
|
+
IF subkind = NONE THEN '' ELSE subkind END,
|
|
109
|
+
IF world_id = NONE THEN '' ELSE world_id END,
|
|
110
|
+
IF group_id = NONE THEN '' ELSE group_id END,
|
|
111
|
+
IF subject = NONE THEN '' ELSE subject END,
|
|
112
|
+
IF derivation = NONE THEN '' ELSE derivation END,
|
|
113
|
+
IF note = NONE THEN '' ELSE note END,
|
|
114
|
+
IF tags = NONE THEN [] ELSE tags END,
|
|
115
|
+
IF genres = NONE THEN [] ELSE genres END,
|
|
116
|
+
IF tropes = NONE THEN [] ELSE tropes END,
|
|
117
|
+
IF narrative = NONE THEN [] ELSE narrative END,
|
|
118
|
+
IF traits = NONE THEN [] ELSE traits END,
|
|
119
|
+
IF roles = NONE THEN [] ELSE roles END,
|
|
120
|
+
IF relations = NONE THEN [] ELSE relations END,
|
|
121
|
+
IF moods = NONE THEN [] ELSE moods END,
|
|
122
|
+
IF settings = NONE THEN [] ELSE settings END
|
|
123
|
+
]), ' ') WHERE search_text = NONE;`);
|
|
124
|
+
}
|
|
102
125
|
const tableInfo = await db.query('INFO FOR TABLE material;');
|
|
103
126
|
const table = Array.isArray(tableInfo) && tableInfo[0] ? tableInfo[0] : {};
|
|
104
127
|
if (!table.fields || !table.fields.source || !table.fields.kind || !table.fields.name || !table.fields.tags || !table.fields.group_id || !table.fields.subkind
|
|
105
|
-
|| !table.fields.subject || !table.fields.derivation || !table.fields.genres || !table.fields.tropes || !table.fields.narrative
|
|
128
|
+
|| !table.fields.subject || !table.fields.derivation || !table.fields.search_text || !table.fields.genres || !table.fields.tropes || !table.fields.narrative
|
|
106
129
|
|| !table.fields.traits || !table.fields.roles || !table.fields.relations || !table.fields.moods || !table.fields.settings || !table.fields.world_id || !table.fields.rank_order) {
|
|
107
130
|
throw new Error('素材库 schema 初始化后仍未找到 material 的多层标签字段(kind/name/tags/subject/genres/tropes/narrative/traits/roles/relations/moods/settings/world_id/rank_order)。');
|
|
108
131
|
}
|
package/package.json
CHANGED
|
@@ -258,9 +258,13 @@ async function main() {
|
|
|
258
258
|
}
|
|
259
259
|
if (opts.search) {
|
|
260
260
|
const term = q(opts.search);
|
|
261
|
-
|
|
261
|
+
// Name has a full-text index; the facet arrays have normal indexes. This
|
|
262
|
+
// avoids a bulk ngram index over the entire 190k corpus, which is too heavy
|
|
263
|
+
// for the workspace SurrealDB process.
|
|
264
|
+
const arrayFields = ['tags', 'genres', 'tropes', 'narrative', 'traits', 'roles', 'relations', 'moods', 'settings'];
|
|
262
265
|
where.push('(name @1@ ' + term
|
|
263
|
-
+
|
|
266
|
+
+ ' OR subject = ' + term
|
|
267
|
+
+ arrayFields.map((field) => ' OR ' + field + ' CONTAINS ' + term).join('')
|
|
264
268
|
+ ')');
|
|
265
269
|
}
|
|
266
270
|
|