Search in sources :

Example 1 with MessageHit

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

the class SearchWrapper method getChildren.

@Override
public Collection<DavResource> getChildren(DavContext ctxt) {
    ArrayList<DavResource> children = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    try {
        Account account = prov.get(AccountBy.name, user);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        SearchParams params = new SearchParams();
        params.setQueryString(mQuery.toString());
        params.setTypes(SEARCH_TYPES);
        params.setSortBy(SortBy.NAME_ASC);
        params.setFetchMode(SearchParams.Fetch.NORMAL);
        params.setPrefetch(true);
        params.setChunkSize(SEARCH_LIMIT);
        try (ZimbraQueryResults zqr = mbox.index.search(SoapProtocol.Soap12, ctxt.getOperationContext(), params)) {
            while (zqr.hasNext()) {
                ZimbraHit hit = zqr.getNext();
                if (hit instanceof MessageHit)
                    addAttachmentResources((MessageHit) hit, children);
            }
        }
    } catch (Exception e) {
        ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
    }
    return children;
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) Account(com.zimbra.cs.account.Account) SearchParams(com.zimbra.cs.index.SearchParams) Mailbox(com.zimbra.cs.mailbox.Mailbox) MessageHit(com.zimbra.cs.index.MessageHit) ArrayList(java.util.ArrayList) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) Provisioning(com.zimbra.cs.account.Provisioning)

Example 2 with MessageHit

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

the class Search method putHits.

private void putHits(ZimbraSoapContext zsc, OperationContext octxt, Element el, ZimbraQueryResults results, SearchParams params, Map<String, Set<String>> memberOfMap) 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, memberOfMap);
    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)

Example 3 with MessageHit

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

the class SearchConv method determineExpandedMessages.

/**
 * Determine which messages in a conversation need to be expanded. This combines logic
 * that used to be in SearchResults.isInlineExpand and SearchConv.putHits.
 * Returns a boolean array with true/false corresponding to whether each message should
 * be expanded.
 */
private boolean[] determineExpandedMessages(ExpandResults expand, ZimbraHit[] matched, List<Message> msgs, Conversation conv, int offset, int size) throws ServiceException {
    int numMatched = 0;
    boolean forceExpandFirstMsg;
    boolean[] expandMsgs = new boolean[size];
    if (expand == ExpandResults.FIRST_MSG || expand == ExpandResults.HITS_OR_FIRST_MSG || expand == ExpandResults.U_OR_FIRST_MSG || expand == ExpandResults.U1_OR_FIRST_MSG) {
        forceExpandFirstMsg = true;
    } else {
        forceExpandFirstMsg = false;
    }
    for (int i = offset; i < offset + size; i++) {
        boolean shouldExpand;
        if (matched[i - offset] != null) {
            numMatched++;
            MessageHit hit = (MessageHit) matched[i - offset];
            Message msg = hit.getMessage();
            if (expand == ExpandResults.FIRST) {
                shouldExpand = numMatched == 1;
            } else if (expand == ExpandResults.ALL || expand == ExpandResults.HITS) {
                shouldExpand = true;
            } else if (expand == ExpandResults.HITS_OR_FIRST_MSG) {
                forceExpandFirstMsg = false;
                shouldExpand = true;
            } else if (expand == ExpandResults.UNREAD) {
                shouldExpand = msg.isUnread();
            } else if (expand == ExpandResults.U_OR_FIRST_MSG) {
                shouldExpand = msg.isUnread();
                if (forceExpandFirstMsg == true) {
                    forceExpandFirstMsg = !shouldExpand;
                }
            } else if (expand == ExpandResults.UNREAD_FIRST) {
                shouldExpand = conv.getUnreadCount() == 0 ? numMatched == 1 : msg.isUnread();
            } else if (expand == ExpandResults.U1_OR_FIRST_MSG) {
                if (conv.getUnreadCount() > 0) {
                    forceExpandFirstMsg = false;
                }
                shouldExpand = conv.getUnreadCount() == 0 ? numMatched == 1 : msg.isUnread();
            } else {
                shouldExpand = expand.matches(hit.getParsedItemID());
            }
        } else {
            Message msg = msgs.get(i);
            shouldExpand = expand == ExpandResults.ALL || expand.matches(msg);
        }
        expandMsgs[i - offset] = shouldExpand;
    }
    if (forceExpandFirstMsg == true || expand == ExpandResults.FIRST_MSG) {
        expandMsgs[0] = true;
    }
    return expandMsgs;
}
Also used : Message(com.zimbra.cs.mailbox.Message) MessageHit(com.zimbra.cs.index.MessageHit)

Example 4 with MessageHit

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

the class SearchResponse method add.

/* We need to pass in a boolean signifying whether to expand the message or not (bug 75990)
    */
void add(ZimbraHit hit, boolean expandMsg) throws ServiceException {
    Element el = null;
    if (params.getFetchMode() == SearchParams.Fetch.IDS) {
        if (hit instanceof ConversationHit) {
            // need to expand the contained messages
            el = element.addElement(MailConstants.E_HIT);
            el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(hit.getParsedItemID()));
        } else {
            el = element.addElement(MailConstants.E_HIT);
            el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(hit.getParsedItemID()));
        }
    } else if (hit instanceof ProxiedHit) {
        element.addElement(((ProxiedHit) hit).getElement().detach());
        size++;
        return;
    } else {
        if (hit instanceof ConversationHit) {
            el = add((ConversationHit) hit);
        } else if (hit instanceof MessageHit) {
            el = add((MessageHit) hit, expandMsg);
        } else if (hit instanceof MessagePartHit) {
            el = add((MessagePartHit) hit);
        } else if (hit instanceof ContactHit) {
            el = add((ContactHit) hit);
        } else if (hit instanceof NoteHit) {
            el = add((NoteHit) hit);
        } else if (hit instanceof CalendarItemHit) {
            // el could be null
            el = add((CalendarItemHit) hit);
        } else if (hit instanceof DocumentHit) {
            el = add((DocumentHit) hit);
        } else {
            LOG.error("Got an unknown hit type putting search hits: " + hit);
            return;
        }
    }
    if (el != null) {
        size++;
        el.addAttribute(MailConstants.A_SORT_FIELD, hit.getSortField(sortOrder).toString());
        if (includeMailbox) {
            el.addAttribute(MailConstants.A_ID, new ItemId(hit.getAcctIdStr(), hit.getItemId()).toString());
        }
    }
}
Also used : NoteHit(com.zimbra.cs.index.NoteHit) MessagePartHit(com.zimbra.cs.index.MessagePartHit) ProxiedHit(com.zimbra.cs.index.ProxiedHit) ConversationHit(com.zimbra.cs.index.ConversationHit) ContactHit(com.zimbra.cs.index.ContactHit) DocumentHit(com.zimbra.cs.index.DocumentHit) CalendarItemHit(com.zimbra.cs.index.CalendarItemHit) Element(com.zimbra.common.soap.Element) MessageHit(com.zimbra.cs.index.MessageHit) ItemId(com.zimbra.cs.service.util.ItemId)

Example 5 with MessageHit

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

the class SearchResponse method add.

private Element add(ConversationHit hit) throws ServiceException {
    if (params.getFetchMode() == SearchParams.Fetch.IDS) {
        Element el = element.addNonUniqueElement(MailConstants.E_CONV);
        for (MessageHit mhit : hit.getMessageHits()) {
            ConversationMsgHitInfo cMsgHit = new ConversationMsgHitInfo(ifmt.formatItemId(mhit.getItemId()));
            cMsgHit.toElement(el);
        }
        return el;
    } else {
        Conversation conv = hit.getConversation();
        MessageHit mhit = hit.getFirstMessageHit();
        Element el = ToXML.encodeConversationSummary(element, ifmt, octxt, conv, mhit == null ? null : mhit.getMessage(), params.getWantRecipients());
        Collection<MessageHit> msgHits = hit.getMessageHits();
        long numMsgs = el.getAttributeLong(MailConstants.A_NUM, 0);
        if (!params.fullConversation() || numMsgs == msgHits.size()) {
            for (MessageHit mh : msgHits) {
                Message msg = mh.getMessage();
                doConvMsgHit(el, msg, numMsgs);
            }
        } else {
            for (Message msg : conv.getMailbox().getMessagesByConversation(octxt, conv.getId(), SortBy.DATE_DESC, -1, /* limit */
            false)) {
                doConvMsgHit(el, msg, numMsgs);
            }
        }
        return el;
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) Element(com.zimbra.common.soap.Element) MessageHit(com.zimbra.cs.index.MessageHit) ConversationMsgHitInfo(com.zimbra.soap.mail.type.ConversationMsgHitInfo) Conversation(com.zimbra.cs.mailbox.Conversation)

Aggregations

MessageHit (com.zimbra.cs.index.MessageHit)8 ZimbraHit (com.zimbra.cs.index.ZimbraHit)5 Message (com.zimbra.cs.mailbox.Message)4 Element (com.zimbra.common.soap.Element)3 ZimbraQueryResults (com.zimbra.cs.index.ZimbraQueryResults)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Account (com.zimbra.cs.account.Account)2 Provisioning (com.zimbra.cs.account.Provisioning)2 ResultsPager (com.zimbra.cs.index.ResultsPager)2 ExpandResults (com.zimbra.cs.index.SearchParams.ExpandResults)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ServiceException (com.zimbra.common.service.ServiceException)1 ShareNotification (com.zimbra.common.share.ShareNotification)1 DavException (com.zimbra.cs.dav.DavException)1 CalendarItemHit (com.zimbra.cs.index.CalendarItemHit)1 ContactHit (com.zimbra.cs.index.ContactHit)1 ConversationHit (com.zimbra.cs.index.ConversationHit)1 DocumentHit (com.zimbra.cs.index.DocumentHit)1 MessagePartHit (com.zimbra.cs.index.MessagePartHit)1