RavenDb - Recursive queries/indexes, for Hierarchical Document

一世执手 提交于 2019-12-13 13:15:13

问题


I know this might be a bit of a silly question, probably doing it wrong but I'll ask any way.

Lets say I have a set of Hierarchical Documents. The only information they contain about their place in the hierarchy is their parent id. If its null we have reached the top.

Getting parents and children are the easy part.

What I want to do is query for all the descendants and ancestors. I think I have to parts to this question. 1) To get the ancestors to a document is their any way to make a recursive query? Get the parent parent until parent is null.

2) Is their any way to make a index/projections where we can map the ancestor ids to a document. And then query the ancestor id or the document id? Because if I could get that index it would be easy to say get all documents by ancestor id for document id equal to the documentid i want to get the children from.

Lets say I have this structure.

Document 1
Document 1.1
Document 1.1.1
Document 1.1.2
Document 1.2
Document 1.2.1

I want a index looking somthing like this

DocumentID
1.1
1.1.1
1.1.1
1.1.2
1.1.2
1.2
1.2.1
1.2.1

AncestorID 1
1
1.1
1
1.1
1
1.2


回答1:


This was discussed in detail on the RavenDB mailing list: https://groups.google.com/d/topic/ravendb/ptBYL9A5PA8/discussion

The chosen solution, I believe, involved putting the full ancestry in each document.



来源:https://stackoverflow.com/questions/4471005/ravendb-recursive-queries-indexes-for-hierarchical-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!