我正在研究一种可以轻松搜索的文档结构,同时保持可重建的结构。我的意思是文档本身包含 CMS 构建更新文档所需的表单所需的信息。
关键是永远不会知道文档的最终结构,因为它将通过 CMS 构建/修改。
目标是确保前端内容方法可以快速搜索,同时使 CMS 能够重建内容以便对其进行管理。我对让 CMS 的管理区域更努力地工作毫不犹豫,速度在那里并不那么重要。
这是一个基本示例
这是一个高度缩写的文件,但它可以说明我的观点。该文档相对容易查询,但它没有关于 CMS 如何显示它的结构信息。
{
"name" : "Page Name",
"title" : "Page Title",
"description" : "Page Description",
"page_heading" : "New Heading",
"content_body" : "<p>New Content</p>",
"slideshow" :
[
{
"image_title" : "Vacation Hawaii",
"image_file" : "hawaii100.jpg"
},
{
"image_title" : "Vacation Spain",
"image_file" : "Spain200.jpg"
},
]
}
这是一个带有缩写结构数据的示例
这种方法的问题是查询变得更加困难。
> db.posts.find( { page_heading.value : "example" } )
--
{
"name" : "Page Name",
"title" : "Page Title",
"description" : "Page Description",
"page_heading" :
{
"value" : "This is the page heading",
"type" : "string",
},
"content_body" :
{
"value" : "<p>HTML Content</p>",
"type" : "html_textarea",
},
"slideshow" :
{
"type" :
{
"image_title" : "string",
"image_file" : "file"
},
"value" :
[
{
"image_title" : "Vacation Hawaii",
"image_file" : "hawaii100.jpg"
},
{
"image_title" : "Vacation Spain",
"image_file" : "Spain200.jpg"
},
]
}
}
替代方法
拥有单独的文档,一个用于数据,一个用于模板,似乎是一种可能的解决方案,但会稍微增加后勤复杂性。
链接到模板的内容文档
{
"name" : "Page Name",
"title" : "Page Title",
"description" : "Page Description",
"template" : "document_id",
"page_heading" : "New Heading",
"content_body" : "<p>New Content</p>",
"slideshow" :
[
{
"image_title" : "Vacation Hawaii",
"image_file" : "hawaii100.jpg"
},
{
"image_title" : "Vacation Spain",
"image_file" : "Spain200.jpg"
},
]
}
模板文件
{
"parent" : "document_id",
"page_heading" :
{
"type" : "string",
"required" : true
},
"content_body" :
{
"type" : "html_textarea",
"required" : true
},
"slideshow" :
{
"type" :
{
"image_title" : "string",
"image_file" : "file"
}
}
}
最好的方法是什么?
我很有可能把整个事情复杂化了,而我面前有一个简单的解决方案。