use of com.zimbra.cs.index.ZimbraQueryResults in project zm-mailbox by Zimbra.
the class TestUtil method search.
/**
* Searches a mailbox and returns the id's of all matching items.
*/
public static List<Integer> search(Mailbox mbox, String query, Set<MailItem.Type> types) throws ServiceException {
List<Integer> ids = new ArrayList<Integer>();
ZimbraQueryResults r = mbox.index.search(new OperationContext(mbox), query, types, SortBy.DATE_DESC, 100);
while (r.hasNext()) {
ZimbraHit hit = r.getNext();
ids.add(new Integer(hit.getItemId()));
}
Closeables.closeQuietly(r);
return ids;
}
use of com.zimbra.cs.index.ZimbraQueryResults in project zm-mailbox by Zimbra.
the class TestUnread method testSearch.
/**
* Makes sure that something comes back when searching for unread items.
*/
@Test
public void testSearch() throws Exception {
ZimbraLog.test.debug("Starting Test %s", name.getMethodName());
verifySetUp();
ZimbraQueryResults results = mMbox.index.search(new OperationContext(mMbox), "is:unread", EnumSet.of(MailItem.Type.MESSAGE), SortBy.DATE_DESC, 100);
Assert.assertTrue("No search results found", results.hasNext());
results.close();
}
use of com.zimbra.cs.index.ZimbraQueryResults 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.ZimbraQueryResults in project zm-mailbox by Zimbra.
the class Formatter method getMailItems.
// Caller is responsible for filtering out Appointments/Tasks marked private if the requester
// is not the mailbox owner.
public Iterator<? extends MailItem> getMailItems(UserServletContext context, long startTime, long endTime, long chunkSize) throws ServiceException {
if (context.requestedItems != null) {
return context.getRequestedItems();
}
assert (context.target != null);
String query = context.getQueryString();
if (query != null) {
if (context.target instanceof Folder) {
Folder f = (Folder) context.target;
if (f.getId() != Mailbox.ID_FOLDER_USER_ROOT) {
query = "in:" + f.getPath() + " " + query;
}
}
Set<MailItem.Type> types;
if (context.getTypesString() == null) {
types = getDefaultSearchTypes();
} else {
try {
types = MailItem.Type.setOf(context.getTypesString());
} catch (IllegalArgumentException e) {
throw MailServiceException.INVALID_TYPE(e.getMessage());
}
}
ZimbraQueryResults results = context.targetMailbox.index.search(context.opContext, query, types, context.sortBy, context.getOffset() + context.getLimit());
return new QueryResultIterator(results);
} else if (context.target instanceof Folder) {
Collection<? extends MailItem> items = getMailItemsFromFolder(context, (Folder) context.target, startTime, endTime, chunkSize);
return items != null ? items.iterator() : null;
} else {
ArrayList<MailItem> result = new ArrayList<MailItem>();
result.add(context.target);
return result.iterator();
}
}
use of com.zimbra.cs.index.ZimbraQueryResults in project zm-mailbox by Zimbra.
the class MessageTest method moveOutOfSpam.
@Test
public void moveOutOfSpam() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
mbox.getAccount().setJunkMessagesIndexingEnabled(false);
DeliveryOptions opt = new DeliveryOptions();
opt.setFolderId(Mailbox.ID_FOLDER_SPAM);
Message msg = mbox.addMessage(null, new ParsedMessage("From: spammer@zimbra.com\r\nTo: test@zimbra.com".getBytes(), false), opt, null);
MailboxTestUtil.index(mbox);
SearchParams params = new SearchParams();
params.setSortBy(SortBy.NONE);
params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
params.setQueryString("from:spammer");
ZimbraQueryResults result = mbox.index.search(SoapProtocol.Soap12, new OperationContext(mbox), params);
Assert.assertFalse(result.hasNext());
mbox.move(new OperationContext(mbox), msg.getId(), MailItem.Type.MESSAGE, Mailbox.ID_FOLDER_INBOX);
MailboxTestUtil.index(mbox);
result = mbox.index.search(SoapProtocol.Soap12, new OperationContext(mbox), params);
Assert.assertTrue(result.hasNext());
Assert.assertEquals(msg.getId(), result.getNext().getItemId());
}
Aggregations