use of com.zimbra.cs.index.ResultsPager in project zm-mailbox by Zimbra.
the class GalSearchControl method doLocalGalAccountSearch.
private boolean doLocalGalAccountSearch(Account galAcct) {
ZimbraQueryResults zqr = null;
try {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(galAcct);
SearchParams searchParams = mParams.getSearchParams();
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;
} finally {
Closeables.closeQuietly(zqr);
}
return true;
}
use of com.zimbra.cs.index.ResultsPager 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());
}
Aggregations