Search in sources :

Example 1 with ResultsPager

use of com.zimbra.cs.index.ResultsPager in project zm-mailbox by Zimbra.

the class GalSearchControl method doLocalGalAccountSearch.

private boolean doLocalGalAccountSearch(Account galAcct) {
    ZimbraQueryResults zqr = null;
    try {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(galAcct);
        SearchParams searchParams = mParams.getSearchParams();
        zqr = mbox.index.search(SoapProtocol.Soap12, new OperationContext(mbox), searchParams);
        ResultsPager pager = ResultsPager.create(zqr, searchParams);
        GalSearchResultCallback callback = mParams.getResultCallback();
        int num = 0;
        while (pager.hasNext()) {
            ZimbraHit hit = pager.getNextHit();
            if (hit instanceof ContactHit) {
                Element contactElem = callback.handleContact(((ContactHit) hit).getContact());
                if (contactElem != null)
                    contactElem.addAttribute(MailConstants.A_SORT_FIELD, hit.getSortField(pager.getSortOrder()).toString());
            }
            num++;
            if (num == mParams.getLimit())
                break;
        }
        callback.setSortBy(zqr.getSortBy().toString());
        callback.setQueryOffset(searchParams.getOffset());
        callback.setHasMoreResult(pager.hasNext());
    } catch (Exception e) {
        ZimbraLog.gal.warn("search on GalSync account failed for %s", galAcct.getId(), e);
        return false;
    } finally {
        Closeables.closeQuietly(zqr);
    }
    return true;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ZimbraHit(com.zimbra.cs.index.ZimbraHit) SearchParams(com.zimbra.cs.index.SearchParams) Mailbox(com.zimbra.cs.mailbox.Mailbox) ContactHit(com.zimbra.cs.index.ContactHit) ResultsPager(com.zimbra.cs.index.ResultsPager) Element(com.zimbra.common.soap.Element) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 2 with ResultsPager

use of com.zimbra.cs.index.ResultsPager in project zm-mailbox by Zimbra.

the class Search method putHits.

private void putHits(ZimbraSoapContext zsc, OperationContext octxt, Element el, ZimbraQueryResults results, SearchParams params) throws ServiceException {
    if (params.getInlineRule() == ExpandResults.HITS || params.getInlineRule() == ExpandResults.FIRST_MSG || params.getInlineRule() == ExpandResults.HITS_OR_FIRST_MSG || params.getInlineRule() == ExpandResults.UNREAD || params.getInlineRule() == ExpandResults.UNREAD_FIRST || params.getInlineRule() == ExpandResults.U_OR_FIRST_MSG || params.getInlineRule() == ExpandResults.U1_OR_FIRST_MSG) {
        // these are not valid values for Search (according to soap.txt)
        params.setInlineRule(ExpandResults.NONE);
    }
    ResultsPager pager = ResultsPager.create(results, params);
    if (params.getCursor() != null) {
        if (params.getCursor().isIncludeOffset()) {
            long offset = pager.getCursorOffset();
            if (offset >= 0) {
                el.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
            }
        }
    } else {
        el.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    }
    SearchResponse resp = new SearchResponse(zsc, octxt, el, params);
    resp.setIncludeMailbox(false);
    resp.setSortOrder(pager.getSortOrder());
    boolean expand;
    ExpandResults expandValue = params.getInlineRule();
    int hitNum = 0;
    while (pager.hasNext() && resp.size() < params.getLimit()) {
        hitNum++;
        ZimbraHit hit = pager.getNextHit();
        if (hit instanceof MessageHit) {
            /*
                 * Determine whether or not to expand MessageHits.
                 * This logic used to be in SearchResponse.isInlineExpand, but was moved
                 * to the handler classes because in some cases
                 * the decision to expand any particular hit is dependent on
                 * other hits (see SearchConv)
                 */
            if (expandValue == ExpandResults.NONE) {
                expand = false;
            } else if (expandValue == ExpandResults.ALL) {
                expand = true;
            } else if (expandValue == ExpandResults.FIRST) {
                expand = params.getOffset() > 0 ? false : hitNum == 1;
            } else {
                expand = expandValue.matches(hit.getParsedItemID());
            }
            resp.add(hit, expand);
        } else {
            resp.add(hit);
        }
    }
    resp.addHasMore(pager.hasNext());
    resp.add(results.getResultInfo());
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) ExpandResults(com.zimbra.cs.index.SearchParams.ExpandResults) ResultsPager(com.zimbra.cs.index.ResultsPager) MessageHit(com.zimbra.cs.index.MessageHit)

Aggregations

ResultsPager (com.zimbra.cs.index.ResultsPager)2 ZimbraHit (com.zimbra.cs.index.ZimbraHit)2 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 ContactHit (com.zimbra.cs.index.ContactHit)1 MessageHit (com.zimbra.cs.index.MessageHit)1 SearchParams (com.zimbra.cs.index.SearchParams)1 ExpandResults (com.zimbra.cs.index.SearchParams.ExpandResults)1 ZimbraQueryResults (com.zimbra.cs.index.ZimbraQueryResults)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 IOException (java.io.IOException)1