JSON 整理与类型生成可运行案例
全文检索结果:从样本起草 Draft-07 Schema
从 全文检索结果 的样本推断字段与类型。样本无法证明全部必填项、合法范围和业务状态,发布前应补正常与异常样本,再用 Schema 校验工具核对。
试一试
在完整工具中打开 ↗示例工作台
JSON 整理与类型生成修改下方数据后重新运行
运行结果
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"ok": {
"type": "boolean"
},
"data": {
"type": "object",
"properties": {
"hits": {
"type": "array",
"items": {
"type": "object",
"properties": {
"documentId": {
"type": "string"
},
"title": {
"type": "string"
},
"score": {
"type": "integer"
},
"highlighted": {
"type": "boolean"
},
"documentType": {
"type": "string"
},
"match": {
"type": "object",
"properties": {
"snippets": {
"type": "array",
"items": {
"type": "string"
}
},
"fields": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"snippets",
"fields"
]
}
},
"required": [
"documentId",
"title",
"score",
"highlighted",
"documentType",
"match"
]
}
},
"summary": {
"type": "object",
"properties": {
"total": {
"type": "integer"
},
"note": {
"type": "null"
}
},
"required": [
"total",
"note"
]
}
},
"required": [
"hits",
"summary"
]
}
},
"required": [
"ok",
"data"
]
}原例已核验,可修改输入后重新运行。
⌘ / Ctrl + Enter 运行01
场景与操作说明
全文检索结果包含文档标识、分数、类型和命中的文本片段。下面的指南与参考文档各有命中字段列表,可练习提取标题、保留结果顺序和比较评分类型;分数只在同一查询口径下解释。
score 为演示非负整数,不能当作跨查询可比较的绝对质量评分。
- 核对 全文检索结果 的字段层级,保留 documentId 的字符串类型。
- 修改一项输入并运行,观察结果中的值或路径如何变化。
- 载入对照样本,复现下面的变化;恢复原例会替换当前输入。
02
对照样本
对照样本没有 hits 元素,无法推断元素结构。比较两份 Schema,确认哪些约束来自样本证据,哪些仍需人工补充。
查看对照输入
{
"ok": true,
"data": {
"hits": [],
"summary": {
"total": 2,
"note": null
}
}
}对照样本的实际结果
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"ok": {
"type": "boolean"
},
"data": {
"type": "object",
"properties": {
"hits": {
"type": "array",
"items": {}
},
"summary": {
"type": "object",
"properties": {
"total": {
"type": "integer"
},
"note": {
"type": "null"
}
},
"required": [
"total",
"note"
]
}
},
"required": [
"hits",
"summary"
]
}
},
"required": [
"ok",
"data"
]
}