[英]Get children with Lucene's TaxonomyReader
In Lucene
, I am using the TaxonomyReader
to read an index of a taxonomy stored in my disk. 在
Lucene
,我正在使用TaxonomyReader
读取存储在磁盘中的分类索引。 For a given category, I need to find all categories that are its children. 对于给定的类别,我需要找到属于其子类别的所有类别。 However, in the Lucene's API I could find a method to retrieve the parent but not with the children.
但是,在Lucene的API中,我可以找到一种方法来检索父级而不是子级。 There is a method called
getChildrenArrays()
that returns a ChildrenArrays object. 有一个名为
getChildrenArrays()
的方法,该方法返回ChildrenArrays对象。 As you can see, this class only has two methods: 如您所见,此类仅具有两个方法:
getYoungestChildArray
getOlderSiblingArray
I want to implement Enumerator
using these two methods. 我想使用这两种方法实现
Enumerator
。 Does someone know how to do it? 有人知道怎么做吗?
I got the following: 我得到以下内容:
private class EnumChildren implements Enumeration<Integer> {
int category, current;
int[] next, first;
public EnumChildren(int category) {
ChildrenArrays childrenArrays = tr.getChildrenArrays();
first = childrenArrays.getYoungestChildArray();
next = childrenArrays.getOlderSiblingArray();
current = first[category];
}
public boolean hasChildren() {
return (current != TaxonomyReader.INVALID_ORDINAL);
}
@Override
public boolean hasMoreElements() {
current = next[current];
return (current != TaxonomyReader.INVALID_ORDINAL);
}
@Override
public Integer nextElement() {
return current;
}
}
Ans is used as: Ans用作:
ordinal = tr.getOrdinal(new CategoryPath(nodeCategory.getPath(), '/'));
EnumChildren childrenEnumeration = new EnumChildren(ordinal);
if (childrenEnumeration.hasChildren()) {
do {
int current = childrenEnumeration.nextElement();
Category child = new Category(tr.getPath(current).toString());
addChildren(child);
nodeCategory.children.add(child);
} while (childrenEnumeration.hasMoreElements());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.