use of com.zimbra.cs.index.SearchParams in project zm-mailbox by Zimbra.
the class GalSearchParams method createSearchParams.
public void createSearchParams(String searchQuery) {
mSearchParams = new SearchParams();
mSearchParams.setLimit(mLimit + 1);
mSearchParams.setSortBy(SortBy.NAME_ASC);
mSearchParams.setQueryString(searchQuery);
mSearchParams.setTypes(EnumSet.of(MailItem.Type.CONTACT));
}
use of com.zimbra.cs.index.SearchParams in project zm-mailbox by Zimbra.
the class GetConv method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element econv = request.getElement(MailConstants.E_CONV);
ItemId iid = new ItemId(econv.getAttribute(MailConstants.A_ID), zsc);
SearchParams params = new SearchParams();
params.setInlineRule(ExpandResults.valueOf(econv.getAttribute(MailConstants.A_FETCH, null), zsc));
if (params.getInlineRule() != ExpandResults.NONE) {
params.setWantHtml(econv.getAttributeBool(MailConstants.A_WANT_HTML, false));
params.setMaxInlinedLength((int) econv.getAttributeLong(MailConstants.A_MAX_INLINED_LENGTH, -1));
params.setWantExpandGroupInfo(econv.getAttributeBool(MailConstants.A_NEED_EXP, false));
for (Element eHdr : econv.listElements(MailConstants.A_HEADER)) {
params.addInlinedHeader(eHdr.getAttribute(MailConstants.A_ATTRIBUTE_NAME));
}
}
Conversation conv = mbox.getConversationById(octxt, iid.getId());
if (conv == null) {
throw MailServiceException.NO_SUCH_CONV(iid.getId());
}
List<Message> msgs = mbox.getMessagesByConversation(octxt, conv.getId(), SortBy.DATE_ASC, -1);
if (msgs.isEmpty() && zsc.isDelegatedRequest()) {
throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
}
Element response = zsc.createElement(MailConstants.GET_CONV_RESPONSE);
ToXML.encodeConversation(response, ifmt, octxt, conv, msgs, params);
return response;
}
use of com.zimbra.cs.index.SearchParams in project zm-mailbox by Zimbra.
the class ContactAutoComplete method queryFolders.
private void queryFolders(String str, String generatedQuery, Map<ItemId, Mountpoint> mountpoints, int limit, AutoCompleteResult result) throws ServiceException {
ZimbraQueryResults qres = null;
try {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(getRequestedAcctId());
SearchParams params = new SearchParams();
params.setQueryString(generatedQuery);
params.setDefaultField("contact:");
params.setTypes(CONTACT_TYPES);
params.setSortBy(SortBy.NONE);
params.setLimit(limit + 1);
params.setPrefetch(true);
params.setFetchMode(SearchParams.Fetch.NORMAL);
ZimbraLog.gal.debug("querying contact folders: %s", params.getQueryString());
qres = mbox.index.search(SoapProtocol.Soap12, octxt, params);
while (qres.hasNext()) {
ZimbraHit hit = qres.getNext();
Map<String, String> fields = null;
ItemId id = null;
int fid = 0;
if (hit instanceof ContactHit) {
Contact c = ((ContactHit) hit).getContact();
ZimbraLog.gal.debug("hit: %d", c.getId());
fields = c.getFields();
id = new ItemId(c);
fid = c.getFolderId();
if (returnFullContactData) {
List<Attachment> contactAttachments = c.getAttachments();
if (contactAttachments != null && contactAttachments.size() != 0) {
fields.put("image", c.getId() + "_" + contactAttachments.get(0).getName());
}
}
} else if (hit instanceof ProxiedHit) {
fields = new HashMap<String, String>();
Element top = ((ProxiedHit) hit).getElement();
id = new ItemId(top.getAttribute(MailConstants.A_ID), (String) null);
ZimbraLog.gal.debug("hit: %s", id);
ItemId fiid = new ItemId(top.getAttribute(MailConstants.A_FOLDER), (String) null);
Mountpoint mp = mountpoints.get(fiid);
if (mp != null) {
// if the hit came from a descendant folder of
// the mountpoint, we don't have a peer folder ID.
fid = mp.getId();
} else {
fid = FOLDER_ID_MOUNTPOINT_SUBFOLDER;
}
for (Element elt : top.listElements(MailConstants.E_ATTRIBUTE)) {
try {
String name = elt.getAttribute(MailConstants.A_ATTRIBUTE_NAME);
fields.put(name, elt.getText());
} catch (ServiceException se) {
ZimbraLog.gal.warn("error handling proxied query result " + hit);
}
}
if (returnFullContactData) {
if (fields.containsKey("image")) {
fields.put("image", id.getAccountId() + "_" + id.getId() + "_image");
}
}
} else {
continue;
}
addMatchedContacts(str, fields, fid, id, result);
if (!result.canBeCached) {
return;
}
}
} finally {
Closeables.closeQuietly(qres);
}
}
use of com.zimbra.cs.index.SearchParams in project zm-mailbox by Zimbra.
the class Search method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
Account account = getRequestedAccount(zsc);
OperationContext octxt = getOperationContext(zsc, context);
fixBooleanRecipients(request);
SearchRequest req = JaxbUtil.elementToJaxb(request);
if (Objects.firstNonNull(req.getWarmup(), false)) {
mbox.index.getIndexStore().warmup();
return zsc.createElement(MailConstants.SEARCH_RESPONSE);
}
SearchParams params = SearchParams.parse(req, zsc, account.getPrefMailInitialSearch());
if (params.getLocale() == null) {
params.setLocale(mbox.getAccount().getLocale());
}
if (params.inDumpster() && params.getTypes().contains(MailItem.Type.CONVERSATION)) {
throw ServiceException.INVALID_REQUEST("cannot search for conversations in dumpster", null);
}
if (LC.calendar_cache_enabled.booleanValue()) {
List<String> apptFolderIds = getFolderIdListIfSimpleAppointmentsQuery(params, zsc);
if (apptFolderIds != null) {
Account authAcct = getAuthenticatedAccount(zsc);
Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
runSimpleAppointmentQuery(response, params, octxt, zsc, authAcct, mbox, apptFolderIds);
return response;
}
}
ZimbraQueryResults results = mbox.index.search(zsc.getResponseProtocol(), octxt, params);
try {
// create the XML response Element
Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
// must use results.getSortBy() because the results might have ignored our sortBy
// request and used something else...
response.addAttribute(MailConstants.A_SORTBY, results.getSortBy().toString());
putHits(zsc, octxt, response, results, params);
return response;
} finally {
Closeables.closeQuietly(results);
}
}
use of com.zimbra.cs.index.SearchParams in project zm-mailbox by Zimbra.
the class SearchConv method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
SearchConvRequest req = JaxbUtil.elementToJaxb(request);
boolean nest = ZmBoolean.toBool(req.getNestMessages(), false);
Account acct = getRequestedAccount(zsc);
SearchParams params = SearchParams.parse(req, zsc, acct.getPrefMailInitialSearch());
// append (conv:(convid)) onto the beginning of the queryStr
ItemId cid = new ItemId(req.getConversationId(), zsc);
params.setQueryString("conv:\"" + cid.toString(ifmt) + "\" (" + params.getQueryString() + ')');
// force to group-by-message
params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
Element response = null;
if (cid.belongsTo(mbox)) {
// local
ZimbraQueryResults results = mbox.index.search(zsc.getResponseProtocol(), octxt, params);
try {
response = zsc.createElement(MailConstants.SEARCH_CONV_RESPONSE);
response.addAttribute(MailConstants.A_QUERY_OFFSET, Integer.toString(params.getOffset()));
SortBy sort = results.getSortBy();
response.addAttribute(MailConstants.A_SORTBY, sort.toString());
List<Message> msgs = mbox.getMessagesByConversation(octxt, cid.getId(), sort, -1);
if (msgs.isEmpty() && zsc.isDelegatedRequest()) {
throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
}
// filter out IMAP \Deleted messages from the message lists
Conversation conv = mbox.getConversationById(octxt, cid.getId());
if (conv.isTagged(Flag.FlagInfo.DELETED)) {
List<Message> raw = msgs;
msgs = new ArrayList<Message>();
for (Message msg : raw) {
if (!msg.isTagged(Flag.FlagInfo.DELETED)) {
msgs.add(msg);
}
}
}
Element container = nest ? ToXML.encodeConversationSummary(response, ifmt, octxt, conv, CONVERSATION_FIELD_MASK) : response;
SearchResponse builder = new SearchResponse(zsc, octxt, container, params);
builder.setAllRead(conv.getUnreadCount() == 0);
boolean more = putHits(octxt, ifmt, builder, msgs, results, params, conv);
response.addAttribute(MailConstants.A_QUERY_MORE, more);
// call me AFTER putHits since some of the <info> is generated by the getting of the hits!
builder.add(results.getResultInfo());
} finally {
Closeables.closeQuietly(results);
}
return response;
} else {
// remote
try {
Element proxyRequest = zsc.createElement(MailConstants.SEARCH_CONV_REQUEST);
Account target = Provisioning.getInstance().get(AccountBy.id, cid.getAccountId(), zsc.getAuthToken());
if (target != null) {
params.setInlineRule(params.getInlineRule().toLegacyExpandResults(target.getServer()));
}
params.encodeParams(proxyRequest);
proxyRequest.addAttribute(MailConstants.A_NEST_MESSAGES, nest);
proxyRequest.addAttribute(MailConstants.A_CONV_ID, cid.toString());
// okay, lets run the search through the query parser -- this has the side-effect of
// re-writing the query in a format that is OK to proxy to the other server -- since the
// query has an "AND conv:remote-conv-id" part, the query parser will figure out the right
// format for us. TODO somehow make this functionality a bit more exposed in the
// ZimbraQuery APIs...
String rewrittenQueryString = mbox.getRewrittenQueryString(octxt, params);
proxyRequest.addAttribute(MailConstants.E_QUERY, rewrittenQueryString, Element.Disposition.CONTENT);
// proxy to remote account
response = proxyRequest(proxyRequest, context, target.getId());
return response.detach();
} catch (SoapFaultException e) {
throw ServiceException.FAILURE("SoapFaultException: ", e);
}
}
}
Aggregations