Instead of storing a flat structure, I have tree structure to store in lucene index. While doing a search on tree, I have to return search node as well as all ancestor of that node.
For ex, tree is like below. Its complete geography tree.
Global
| |
Asia North America
| | |
China USA MEXICO
I can think of two ways to store this data in lucene.
1st approach: Capture on parent node of a given node.
name, parent
Asia, Global
China, Asia
USA, North America
Java Object:
Class Node
id ,name
In this approach, lets say I am searching for USA. As per requirement I have to return all ancestors of USA which North America and Global. So I have to do go index in recursive manner.
2nd approach: store ancestors in lucene index also
Java Object:
class Node
id, name, List<Node> ancestors
In this approach, I am capturing ancestors multiple times. Will it create an issue or lucene captures the duplicate values only once ?
Which approach would be better or is there a another good to store tree kind of structure in lucene ?
Thanks.