导出时错误地将 0 个索引字段列为 null,而不是 false 或空数组
作者: lgtmak创建于 2025年8月7日更新于 2025年9月7日
// 配置
{
document: {
id: "id",
store: true,
index: [
{ field: "title", tokenize: "forward" },
],
tag: [ { field: "scoredValue", custom: (data) => Number(data.score) > 1 ? ">1" : false } ]
}
}
// 示例文档
[
{
"id": 1,
"title": "One",
"score": null,
},
{
"id": 2,
"title": "Two",
"score": null,
},
]导出数据库时,会生成如下的索引 json:
{
...
"1.tag": "[[\"scoredValue\", null],[...],[...]]"
}尝试导入时,在 1.tag 这个键上会出现以下错误:
TypeError: Cannot read properties of null (reading 'length')
导入代码:
const docIndex = new Document(name, myConfig);
// 这里 key 是 index 导出的 `1.tag`
for (const key in blobData.indexes) {
docIndex.import(key, blobData.indexes[key]);
}内容来源: nextapps-de/flexsearch