private void calculateChildren() throws IOException {
if (hits == null) {
// collect all context nodes
Map uuids = new HashMap();
final Hits contextHits = new AdaptingHits();
contextScorer.score(new HitCollector() {
public void collect(int doc, float score) {
contextHits.set(doc);
}
});
// read the uuids of the context nodes
for (int i = contextHits.next(); i > -1; i = contextHits.next()) {
String uuid = reader.document(i, FieldSelectors.UUID).get(FieldNames.UUID);
uuids.put(new Integer(i), uuid);
}
// collect all children of the context nodes
Hits childrenHits = new AdaptingHits();
if (nameTestScorer != null) {
Hits nameHits = new ScorerHits(nameTestScorer);
for (int h = nameHits.next(); h > -1; h = nameHits.next()) {
if (uuids.containsKey(new Integer(hResolver.getParent(h)))) {
childrenHits.set(h);
}
}
} else {
// get child node entries for each hit
for (Iterator it = uuids.values().iterator(); it.hasNext(); ) {
String uuid = (String) it.next();
NodeId id = new NodeId(UUID.fromString(uuid));
try {
NodeState state = (NodeState) itemMgr.getItemState(id);
Iterator entries = state.getChildNodeEntries().iterator();
while (entries.hasNext()) {
NodeId childId = ((ChildNodeEntry) entries.next()).getId();
Term uuidTerm = new Term(FieldNames.UUID, childId.getUUID().toString());
TermDocs docs = reader.termDocs(uuidTerm);
try {
if (docs.next()) {
childrenHits.set(docs.doc());
}
} finally {
docs.close();
}
}