Hits luceneHits = searcher.getSearcher().search(q, mLuceneSortDateAsc);
Hits luceneHits = searcher.getSearcher().search(q, getSort(SortBy.DATE_ASCENDING));
    void chkIndex(boolean repair) throws ServiceException     {        synchronized(getLock()) {                    flush();            Connection conn = null;            conn = DbPool.getConnection();            Mailbox mbox = MailboxManager.getInstance().getMailboxById(mMailboxId);            ///////////////////////////////            //            // Stage 1 -- look for missing or extra messages and reindex/delete as necessary.            //            {                DbSearchConstraints c = new DbSearchConstraints();                c.mailbox = mbox;                c.sort = DbMailItem.SORT_BY_DATE;                c.types = new HashSet<Byte>();                c.types.add(MailItem.TYPE_CONTACT);                 c.types.add(MailItem.TYPE_MESSAGE);                c.types.add(MailItem.TYPE_NOTE);                ChkIndexStage1Callback callback = new ChkIndexStage1Callback(this);                DbMailItem.search(callback.msgsInMailbox, conn, c);                mLog.info("Verifying (repair="+(repair?"TRUE":"FALSE")+") Index for Mailbox "+this.mMailboxId+" with "+callback.msgsInMailbox.size()+" items.");                try {                    this.enumerateTermsForField(new Term(LuceneFields.L_MAILBOX_BLOB_ID, ""), callback);                } catch (IOException e) {                    throw ServiceException.FAILURE("Caught IOException while enumerating fields", e);                }                mLog.info("Stage 1 Verification complete for Mailbox "+this.mMailboxId);                if (repair) {                    try {                        mLog.info("Attempting Stage 1 Repair for mailbox "+this.mMailboxId);                        callback.doIndexRepair();                    } catch (IOException e) {                        throw ServiceException.FAILURE("Caught IOException while repairing index", e);                    }                    flush();                }            }            /////////////////////////////////            //            // Stage 2 -- verify SORT_BY_DATE orders match up            //            {                mLog.info("Stage 2 Verify SORT_DATE_ASCENDNIG for Mailbox "+this.mMailboxId);                // SORT_BY__DATE_ASC                DbSearchConstraints c = new DbSearchConstraints();                c.mailbox = mbox;                c.sort = DbMailItem.SORT_BY_DATE | DbMailItem.SORT_ASCENDING;                c.types = new HashSet<Byte>();                c.types.add(MailItem.TYPE_CONTACT);                 c.types.add(MailItem.TYPE_MESSAGE);                c.types.add(MailItem.TYPE_NOTE);                String lucSortField = LuceneFields.L_DATE;                ChkIndexStage2Callback callback = new ChkIndexStage2Callback(this, lucSortField, false);                DbMailItem.search(callback.msgsInMailbox, conn, c);                MailboxIndex.CountedIndexSearcher searcher = null;                try {                    callback.beginIterating();                    searcher = getCountedIndexSearcher();                    TermQuery q = new TermQuery(new Term(LuceneFields.L_ALL, LuceneFields.L_ALL_VALUE));                    Hits luceneHits = searcher.getSearcher().search(q, mLuceneSortDateAsc);                    for (int i = 0; i < luceneHits.length(); i++) {                        callback.onDocument(luceneHits.doc(i));                    }                } catch (IOException e) {                    throw ServiceException.FAILURE("Caught IOException while enumerating fields", e);                } finally {                    if (searcher != null) {                        searcher.release();                    }                }                mLog.info("Stage 2 Verification complete for Mailbox "+this.mMailboxId);            }            /////////////////////////////////            //            // Stage 3 -- verify SORT_BY_DATE orders match up            //            {                mLog.info("Stage 3 Verify SORT_DATE_DESCENDING for Mailbox "+this.mMailboxId);                // SORT_BY__DATE_ASC                DbSearchConstraints c = new DbSearchConstraints();                c.mailbox = mbox;                c.sort = DbMailItem.SORT_BY_DATE | DbMailItem.SORT_DESCENDING;                c.types = new HashSet<Byte>();                c.types.add(MailItem.TYPE_CONTACT);                 c.types.add(MailItem.TYPE_MESSAGE);                c.types.add(MailItem.TYPE_NOTE);                String lucSortField = LuceneFields.L_DATE;                ChkIndexStage2Callback callback = new ChkIndexStage2Callback(this, lucSortField, true);                DbMailItem.search(callback.msgsInMailbox, conn, c);                MailboxIndex.CountedIndexSearcher searcher = null;                try {                    callback.beginIterating();                    searcher = getCountedIndexSearcher();                    TermQuery q = new TermQuery(new Term(LuceneFields.L_ALL, LuceneFields.L_ALL_VALUE));                    Hits luceneHits = searcher.getSearcher().search(q, mLuceneSortDateDesc);                    for (int i = 0; i < luceneHits.length(); i++) {                        callback.onDocument(luceneHits.doc(i));                    }                } catch (IOException e) {                    throw ServiceException.FAILURE("Caught IOException while enumerating fields", e);                } finally {                    if (searcher != null) {                        searcher.release();                    }                }                mLog.info("Stage 3 Verification complete for Mailbox "+this.mMailboxId);            }        }    }