use of com.zimbra.cs.index.SearchParams.ExpandResults 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());
}
use of com.zimbra.cs.index.SearchParams.ExpandResults 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());
}
use of com.zimbra.cs.index.SearchParams.ExpandResults in project zm-mailbox by Zimbra.
the class ToXML method encodeConversation.
public static Element encodeConversation(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Conversation conv, List<Message> msgs, SearchParams params) throws ServiceException {
int fields = NOTIFY_FIELDS;
Element c = encodeConversationSummary(parent, ifmt, octxt, conv, msgs, null, OutputParticipants.PUT_BOTH, fields, true);
if (msgs.isEmpty()) {
return c;
}
c.addAttribute(MailConstants.E_SUBJECT, msgs.get(0).getSubject(), Element.Disposition.CONTENT);
ExpandResults expand = params.getInlineRule();
for (Message msg : msgs) {
if (msg.isTagged(Flag.FlagInfo.DELETED)) {
continue;
}
if (expand == ExpandResults.FIRST || expand == ExpandResults.ALL || expand.matches(msg)) {
encodeMessageAsMP(c, ifmt, octxt, msg, null, params.getMaxInlinedLength(), params.getWantHtml(), params.getNeuterImages(), params.getInlinedHeaders(), true, params.getWantExpandGroupInfo(), LC.mime_encode_missing_blob.booleanValue(), params.getWantContent(), NOTIFY_FIELDS);
if (expand == ExpandResults.FIRST) {
expand = ExpandResults.NONE;
}
} else {
Element m = c.addNonUniqueElement(MailConstants.E_MSG);
m.addAttribute(MailConstants.A_ID, ifmt.formatItemId(msg));
m.addAttribute(MailConstants.A_DATE, msg.getDate());
m.addAttribute(MailConstants.A_SIZE, msg.getSize());
m.addAttribute(MailConstants.A_SUBJECT, msg.getSubject(), Element.Disposition.CONTENT);
;
m.addAttribute(MailConstants.A_FOLDER, ifmt.formatItemId(new ItemId(msg.getMailbox().getAccountId(), msg.getFolderId())));
recordItemTags(m, msg, octxt, fields);
m.addAttribute(MailConstants.E_FRAG, msg.getFragment(), Element.Disposition.CONTENT);
encodeEmail(m, msg.getSender(), EmailType.FROM);
}
}
return c;
}
use of com.zimbra.cs.index.SearchParams.ExpandResults in project zm-mailbox by Zimbra.
the class SearchConv method putHits.
/**
* This will only work for messages. That's OK since we force
* GROUP_BY_MESSAGE here.
*
* @param octxt operation context
* @param el SOAP container to put response data in
* @param msgs list of messages in this conversation
* @param results set of HITS for messages in this conversation which
* matches the search
* @param offset offset in conversation to start at
* @param limit number to return
* @return whether there are more messages in the conversation past
* the specified limit
* @throws ServiceException
*/
private boolean putHits(OperationContext octxt, ItemIdFormatter ifmt, SearchResponse resp, List<Message> msgs, ZimbraQueryResults results, SearchParams params, Conversation conv) throws ServiceException {
int offset = params.getOffset();
int limit = params.getLimit();
int size = msgs.size() <= limit + offset ? msgs.size() - offset : limit;
if (size > 0) {
// Array of ZimbraHit ptrs for matches, 1 entry for every message
// we might return from conv. NULL means no ZimbraHit presumably b/c the message didn't match the search.
// Note that the match for msgs[i] is matched[i-offset]!!!!
ZimbraHit[] matched = new ZimbraHit[size];
// For each hit, see if the hit message is in this conv (msgs).
while (results.hasNext()) {
ZimbraHit hit = results.getNext();
// since only they are getting returned.
for (int i = offset; i < offset + size; i++) {
if (hit.getParsedItemID().equals(new ItemId(msgs.get(i)))) {
matched[i - offset] = hit;
break;
}
}
}
ExpandResults expand = params.getInlineRule();
/* Build a boolean array of which messages should be expanded.
* This consolidates logic from SearchParams.isInlineExpand and the main message loop below
*/
// Okay, we've built the matched[] array. Now iterate through all the messages, and put the message or
// the MATCHED entry into the result
boolean[] expandMsgs = determineExpandedMessages(expand, matched, msgs, conv, offset, size);
for (int i = offset; i < offset + size; i++) {
boolean expandMsg = expandMsgs[i];
if (matched[i - offset] != null) {
resp.add(matched[i - offset], expandMsg);
} else {
Message msg = msgs.get(i);
// boolean inline = expand == ExpandResults.ALL || expand.matches(msg);
addMessageMiss(msg, resp.toElement(), octxt, ifmt, expandMsg, params);
}
}
}
return offset + size < msgs.size();
}
Aggregations