Search in sources :

Example 1 with SearchParams

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

the class MailboxIndex method search.

private ZimbraQueryResults search(ZimbraQuery zq) throws ServiceException {
    SearchParams params = zq.getParams();
    ZimbraLog.search.debug("query: %s", params.getQueryString());
    ZimbraLog.searchstat.debug("query: %s", zq.toSanitizedtring());
    // handle special-case Task-only sorts: convert them to a "normal sort" and then re-sort them at the end
    // TODO: this hack (converting the sort) should be able to go away w/ the new SortBy implementation, if the
    // lower-level code was modified to use the SortBy.Criterion and SortBy.Direction data (instead of switching on
    // the SortBy itself). We still will need this switch so that we can wrap the results in ReSortingQueryResults.
    boolean isTaskSort = false;
    boolean isLocalizedSort = false;
    boolean isReadSort = false;
    SortBy originalSort = params.getSortBy();
    switch(originalSort) {
        case TASK_DUE_ASC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_DUE_DESC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_STATUS_ASC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_STATUS_DESC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_PERCENT_COMPLETE_ASC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_PERCENT_COMPLETE_DESC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case READ_ASC:
            isReadSort = true;
            params.setSortBy(SortBy.READ_ASC);
            break;
        case READ_DESC:
            isReadSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case NAME_LOCALIZED_ASC:
        case NAME_LOCALIZED_DESC:
            isLocalizedSort = true;
            break;
    }
    ZimbraQueryResults results = zq.execute();
    if (isTaskSort || isReadSort) {
        results = new ReSortingQueryResults(results, originalSort, null);
    }
    if (isLocalizedSort) {
        results = new ReSortingQueryResults(results, originalSort, params);
    }
    return results;
}
Also used : SearchParams(com.zimbra.cs.index.SearchParams) SortBy(com.zimbra.cs.index.SortBy) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) ReSortingQueryResults(com.zimbra.cs.index.ReSortingQueryResults)

Example 2 with SearchParams

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

the class MailboxIndex method search.

public ZimbraQueryResults search(OperationContext octxt, String queryString, Set<MailItem.Type> types, SortBy sortBy, int chunkSize, boolean inDumpster) throws ServiceException {
    SearchParams params = new SearchParams();
    params.setQueryString(queryString);
    params.setTimeZone(null);
    params.setLocale(null);
    params.setTypes(types);
    params.setSortBy(sortBy);
    params.setChunkSize(chunkSize);
    params.setPrefetch(true);
    params.setFetchMode(SearchParams.Fetch.NORMAL);
    params.setInDumpster(inDumpster);
    return search(SoapProtocol.Soap12, octxt, params);
}
Also used : SearchParams(com.zimbra.cs.index.SearchParams)

Example 3 with SearchParams

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

the class GalSearchControl method doLocalGalAccountSearch.

private boolean doLocalGalAccountSearch(Account galAcct) {
    try {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(galAcct);
        SearchParams searchParams = mParams.getSearchParams();
        try (ZimbraQueryResults 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;
    }
    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) HttpException(org.apache.http.HttpException) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) ContainerException(com.zimbra.common.soap.Element.ContainerException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 4 with SearchParams

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));
}
Also used : SearchParams(com.zimbra.cs.index.SearchParams)

Example 5 with SearchParams

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 {
    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());
    try (ZimbraQueryResults 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;
            }
        }
    } catch (IOException e) {
    }
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) SearchParams(com.zimbra.cs.index.SearchParams) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Attachment(com.zimbra.cs.mailbox.Contact.Attachment) IOException(java.io.IOException) ItemId(com.zimbra.cs.service.util.ItemId) GalContact(com.zimbra.cs.account.GalContact) ProxiedHit(com.zimbra.cs.index.ProxiedHit) ContactHit(com.zimbra.cs.index.ContactHit) ServiceException(com.zimbra.common.service.ServiceException) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults)

Aggregations

SearchParams (com.zimbra.cs.index.SearchParams)13 ZimbraQueryResults (com.zimbra.cs.index.ZimbraQueryResults)9 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 Element (com.zimbra.common.soap.Element)5 ZimbraHit (com.zimbra.cs.index.ZimbraHit)5 IOException (java.io.IOException)5 ServiceException (com.zimbra.common.service.ServiceException)4 OperationContext (com.zimbra.cs.mailbox.OperationContext)4 Account (com.zimbra.cs.account.Account)3 ContactHit (com.zimbra.cs.index.ContactHit)3 ItemId (com.zimbra.cs.service.util.ItemId)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 SoapFaultException (com.zimbra.common.soap.SoapFaultException)2 SortBy (com.zimbra.cs.index.SortBy)2 Conversation (com.zimbra.cs.mailbox.Conversation)2 Message (com.zimbra.cs.mailbox.Message)2 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 ZMailbox (com.zimbra.client.ZMailbox)1