use of org.apache.jackrabbit.core.query.lucene.QueryHits 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();
}
}
}
Aggregations