}  mLuceneSortDateDesc = new Sort(new SortField(LuceneFields.L_DATE, SortField.STRING, true)); mLuceneSortDateAsc = new Sort(new SortField(LuceneFields.L_DATE, SortField.STRING, false)); mLuceneSortSubjectDesc = new Sort(new SortField(LuceneFields.L_SORT_SUBJECT, SortField.STRING, true)); mLuceneSortSubjectAsc = new Sort(new SortField(LuceneFields.L_SORT_SUBJECT, SortField.STRING, false)); mLuceneSortNameDesc = new Sort(new SortField(LuceneFields.L_SORT_NAME, SortField.STRING, true)); mLuceneSortNameAsc = new Sort(new SortField(LuceneFields.L_SORT_NAME, SortField.STRING, false));
}  mLatestSort = new Sort(new SortField(LuceneFields.L_DATE, SortField.STRING, true)); mLatestSortBy = SortBy.DATE_DESCENDING;
    public MailboxIndex(Mailbox mbox, String root) throws ServiceException {        int mailboxId = mbox.getId();        if (mLog.isDebugEnabled())            mLog.debug("Opening Index for mailbox " + mailboxId);        mIndexWriter = null;        mMailboxId = mailboxId;        mMailbox = mbox;        Volume indexVol = Volume.getById(mbox.getIndexVolume());        String idxParentDir = indexVol.getMailboxDir(mailboxId, Volume.TYPE_INDEX);        // this must be different from the idxParentDir (see the IMPORTANT comment below)        mIdxPath = idxParentDir + File.separatorChar + '0';        {            File parentDirFile = new File(idxParentDir);            // IMPORTANT!  Don't make the actual index directory (mIdxPath) yet!              //            // The runtime open-index code checks the existance of the actual index directory:              // if it does exist but we cannot open the index, we do *NOT* create it under the             // assumption that the index was somehow corrupted and shouldn't be messed-with....on the             // other hand if the index dir does NOT exist, then we assume it has never existed (or             // was deleted intentionally) and therefore we should just create an index.            if (!parentDirFile.exists())                parentDirFile.mkdirs();            if (!parentDirFile.canRead()) {                throw ServiceException.FAILURE("Cannot READ index directory (mailbox="+mbox.getId()+ " idxPath="+mIdxPath+")", null);            }            if (!parentDirFile.canWrite()) {                throw ServiceException.FAILURE("Cannot WRITE index directory (mailbox="+mbox.getId()+ " idxPath="+mIdxPath+")", null);            }            // the Lucene code does not atomically swap the "segments" and "segments.new"            // files...so it is possible that a previous run of the server crashed exactly in such            // a way that we have a "segments.new" file but not a "segments" file.  We we will check here             // for the special situation that we have a segments.new            // file but not a segments file...            File segments = new File(mIdxPath, "segments");            if (!segments.exists()) {                File segments_new = new File(mIdxPath, "segments.new");                if (segments_new.exists())                     segments_new.renameTo(segments);            }//          } catch(IOException e) {//          throw ServiceException.FAILURE("Error validating index path (mailbox="+mailbox.getId()+ " root="+root+")", e);        }	        mLuceneSortDateDesc = new Sort(new SortField(LuceneFields.L_DATE, SortField.STRING, true));        mLuceneSortDateAsc = new Sort(new SortField(LuceneFields.L_DATE, SortField.STRING, false));        mLuceneSortSubjectDesc = new Sort(new SortField(LuceneFields.L_SORT_SUBJECT, SortField.STRING, true));        mLuceneSortSubjectAsc = new Sort(new SortField(LuceneFields.L_SORT_SUBJECT, SortField.STRING, false));        mLuceneSortNameDesc = new Sort(new SortField(LuceneFields.L_SORT_NAME, SortField.STRING, true));        mLuceneSortNameAsc = new Sort(new SortField(LuceneFields.L_SORT_NAME, SortField.STRING, false));                String analyzerName = mbox.getAccount().getAttr(Provisioning.A_zimbraTextAnalyzer, null);        if (analyzerName != null)            mAnalyzer = ZimbraAnalyzer.getAnalyzer(analyzerName);        else            mAnalyzer = ZimbraAnalyzer.getDefaultAnalyzer();    }