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;
}
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);
}
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;
}
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 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) {
}
}
Aggregations