if (mParams.getEstimateSize() && mSizeEstimate == -1) { mSizeEstimate = DbMailItem.countResults(conn, mConstraints, mbox); }
    private void dbFirstGetNextChunk(Connection conn, Mailbox mbox, byte sort) throws ServiceException {        if (mLog.isDebugEnabled())            mLog.debug("Running a DB-FIRST execution");                do {            //            // (1) Get the next chunk of results from the DB            //            Collection<SearchResult> dbRes = new ArrayList<SearchResult>();            DbMailItem.search(dbRes, conn, mConstraints, mbox, sort, mOffset, MAX_DBFIRST_RESULTS, mExtra);                        if (dbRes.size() < MAX_DBFIRST_RESULTS) {                mEndOfHits = true;            }                        if (dbRes.size() > 0) {                mOffset += dbRes.size();                                //                // (2) for each of the results returned in (1), do a lucene search                //    for "ORIGINAL-LUCENE-PART AND id:(RESULTS-FROM-1-ABOVE)"                //                                // save the original Lucene query, we'll restore it later                BooleanQuery originalQuery = mLuceneOp.getCurrentQuery();                                try {                    BooleanQuery idsQuery = new BooleanQuery();                                        //                    // For each search result, do two things:                    //    -- remember the indexId in a hash, so we can find the SearchResult later                    //    -- add that indexId to our new booleanquery                     //                    HashMap<Integer, List<SearchResult>> mailItemToResultsMap = new HashMap<Integer, List<SearchResult>>();                                        for (SearchResult res : dbRes) {                        List<SearchResult> l = mailItemToResultsMap.get(res.indexId);                        if (l == null) {                            l = new LinkedList<SearchResult>();                            mailItemToResultsMap.put(res.indexId, l);                        }                        l.add(res);                                                idsQuery.add(new TermQuery(new Term(LuceneFields.L_MAILBOX_BLOB_ID, Integer.toString(res.indexId))), false, false);                    }                                        // add the new query to the mLuceneOp's query                    mLuceneOp.addAndedClause(idsQuery, true);                                        boolean hasMore = true;                                        // we have to get ALL of the lucene hits for these ids.  There can very likely be more                    // hits from Lucene then there are DB id's, so we just ask for a large number.                    while(hasMore) {                        mLuceneChunk = mLuceneOp.getNextResultsChunk(MAX_HITS_PER_CHUNK);                                                Collection<Integer> indexIds = mLuceneChunk.getIndexIds();                        if (indexIds.size() < MAX_HITS_PER_CHUNK) {                            hasMore = false;                        }                         for (int indexId : indexIds) {                            List<SearchResult> l = mailItemToResultsMap.get(indexId);                            for (SearchResult sr : l) {                                mDBHits.add(sr);                            }                        }                    }                } finally {                    // restore the query                    mLuceneOp.setCurrentQuery(originalQuery);                }            }                        } while(mDBHits.size() ==0 && !mEndOfHits);    }