this.qname = qname;
this.axis = axis;
}
public boolean indexInfo(Value key, long pointer) throws TerminatedException {
VariableByteInput is;
try {
is = dbTokens.getAsStream(pointer);
} catch (final IOException e) {
LOG.error(e.getMessage(), e);
return true;
}
word.reuse();
if (qname == null)
{WordRef.decode(key, word);}
else
{QNameWordRef.decode(key, word);}
if (matcher.matches(word)) {
try {
while (is.available() > 0) {
if(context != null)
{context.proceed();}
final int storedDocId = is.readInt();
final byte storedSection = is.readByte();
final int termCount = is.readInt();
//Read (variable) length of node IDs + frequency + offsets
final int length = is.readFixedInt();
final DocumentImpl storedDocument = docs.getDoc(storedDocId);
//Exit if the document is not concerned
if (storedDocument == null) {
is.skipBytes(length);
continue;
}
NodeId previous = null;
for (int m = 0; m < termCount; m++) {
NodeId nodeId = broker.getBrokerPool().getNodeFactory().createFromStream(previous, is);
previous = nodeId;
final int freq = is.readInt();
NodeProxy storedNode;
switch (storedSection) {
case TEXT_SECTION :
storedNode = new NodeProxy(storedDocument, nodeId, Node.TEXT_NODE);
break;
case ATTRIBUTE_SECTION :
storedNode = new NodeProxy(storedDocument, nodeId, Node.ATTRIBUTE_NODE);
break;
case QNAME_SECTION :
storedNode = new NodeProxy(storedDocument, nodeId,
qname.getNameType() == ElementValue.ATTRIBUTE ?
Node.ATTRIBUTE_NODE : Node.ELEMENT_NODE);
break;
default :
throw new IllegalArgumentException("Invalid section type in '" + dbTokens.getFile().getName() + "'");
}
if (contextSet != null) {
NodeProxy parentNode;
switch (storedSection) {
case TEXT_SECTION :
case QNAME_SECTION:
parentNode = contextSet.parentWithChild(storedNode,
false, true, NodeProxy.UNKNOWN_NODE_LEVEL);
break;
case ATTRIBUTE_SECTION :
if (contextSet instanceof VirtualNodeSet) {
parentNode = contextSet.parentWithChild(storedNode,
false, true, NodeProxy.UNKNOWN_NODE_LEVEL);
if (parentNode != null && parentNode.getNodeId().equals(nodeId))
{parentNode = null;}
} else {
parentNode = contextSet.get(storedNode);
}
break;
default :
throw new IllegalArgumentException("Invalid section type in '" +
dbTokens.getFile().getName() + "'");
}
if (parentNode != null) {
final Match match = new FTMatch(-1, nodeId, word.toString(), freq);
readOccurrences(freq, is, match, word.length());
final int sizeHint = contextSet.getSizeHint(storedDocument);
if (axis == NodeSet.ANCESTOR) {
parentNode.addMatch(match);
result.add(parentNode, sizeHint);
} else {
storedNode.addMatch(match);
result.add(storedNode, sizeHint);
}
} else
{is.skip(freq);}
} else {
final Match match = new FTMatch(-1, nodeId, word.toString(), freq);
readOccurrences(freq, is, match, word.length());
storedNode.addMatch(match);
result.add(storedNode, Constants.NO_SIZE_HINT);