use of org.apache.jackrabbit.core.query.lucene.ScoreNode in project jackrabbit by apache.
the class QueryConstraint method initMatches.
/**
* Initializes the matches for the constraint query. If the matches are
* already initialized then this method returns immediately.
*
* @param context the evaluation context.
* @throws IOException if an error occurs while reading from the index.
*/
private void initMatches(EvaluationContext context) throws IOException {
if (matches == null) {
Query selectorQuery;
BooleanQuery and = new BooleanQuery();
try {
selectorQuery = factory.create(getSelector());
and.add(selectorQuery, BooleanClause.Occur.MUST);
and.add(constraint, BooleanClause.Occur.MUST);
} catch (RepositoryException e) {
throw Util.createIOException(e);
}
IndexReader reader = context.getIndexReader();
QueryHits hits = context.evaluate(and);
try {
matches = new HashMap<Integer, Float>();
ScoreNode sn;
while ((sn = hits.nextScoreNode()) != null) {
matches.put(sn.getDoc(reader), sn.getScore());
}
} finally {
hits.close();
}
}
}
use of org.apache.jackrabbit.core.query.lucene.ScoreNode in project jackrabbit by apache.
the class ChildNodeConstraint method evaluate.
/**
* {@inheritDoc}
*/
public boolean evaluate(ScoreNode[] row, Name[] selectorNames, EvaluationContext context) throws IOException {
ScoreNode sn = row[getSelectorIndex(selectorNames)];
if (sn == null) {
return false;
}
SessionImpl session = context.getSession();
NodeImpl parent;
try {
parent = (NodeImpl) session.getNodeById(sn.getNodeId()).getParent();
} catch (RepositoryException e) {
return false;
}
return parent.getId().equals(getBaseNodeId(context));
}
use of org.apache.jackrabbit.core.query.lucene.ScoreNode in project jackrabbit by apache.
the class DescendantNodeConstraint method evaluate.
/**
* {@inheritDoc}
*/
public boolean evaluate(ScoreNode[] row, Name[] selectorNames, EvaluationContext context) throws IOException {
NodeId baseId = getBaseNodeId(context);
if (baseId == null) {
return false;
}
ScoreNode sn = row[getSelectorIndex(selectorNames)];
if (sn == null) {
return false;
}
NodeId id = sn.getNodeId();
SessionImpl session = context.getSession();
try {
NodeImpl parent = session.getNodeById(id);
for (; ; ) {
// throws exception if there is no parent
parent = (NodeImpl) parent.getParent();
if (parent.getId().equals(baseId)) {
return true;
}
}
} catch (RepositoryException e) {
return false;
}
}
Aggregations