Search in sources :

Example 1 with QueryHits

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();
        }
    }
}
Also used : ScoreNode(org.apache.jackrabbit.core.query.lucene.ScoreNode) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryHits(org.apache.jackrabbit.core.query.lucene.QueryHits) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) IndexReader(org.apache.lucene.index.IndexReader) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1 QueryHits (org.apache.jackrabbit.core.query.lucene.QueryHits)1 ScoreNode (org.apache.jackrabbit.core.query.lucene.ScoreNode)1 IndexReader (org.apache.lucene.index.IndexReader)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Query (org.apache.lucene.search.Query)1