use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class UserServletUtil method populateContactFields.
public static void populateContactFields(Iterator<? extends MailItem> contacts, Mailbox mbox, OperationContext octxt, ArrayList<Map<String, String>> allContacts, HashSet<String> fields) throws ServiceException {
while (contacts.hasNext()) {
Object obj = contacts.next();
if (obj instanceof Contact) {
Contact c = (Contact) obj;
if (c.isContactGroup()) {
HashMap<String, String> nContacts = new HashMap<String, String>();
// first add all the fields and values
nContacts.putAll(c.getFields());
// remove groupMemeber
nContacts.remove(ContactConstants.A_groupMember);
// then re-calculate the dlist as in 7.X
ContactGroup cg = ContactGroup.init(c, false);
String strs = cg.migrateToDlist(mbox, octxt);
nContacts.put(ContactConstants.A_dlist, strs);
allContacts.add(nContacts);
fields.addAll(nContacts.keySet());
} else {
allContacts.add(c.getFields());
fields.addAll(c.getFields().keySet());
}
}
}
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class AbstractIndexStoreTest method deleteDocument.
@Test
public void deleteDocument() throws Exception {
ZimbraLog.test.debug("--->TEST deleteDocument");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
IndexStore index = mbox.index.getIndexStore();
index.deleteIndex();
Indexer indexer = index.openIndexer();
Assert.assertEquals("maxDocs at start", 0, indexer.maxDocs());
Contact contact1 = createContact(mbox, "James", "Peters", "test1@zimbra.com");
createContact(mbox, "Emma", "Peters", "test2@zimbra.com");
// Make sure all indexing has been done
mbox.index.indexDeferredItems();
ZimbraIndexSearcher searcher = index.openSearcher();
Assert.assertEquals("numDocs after 2 adds", 2, searcher.getIndexReader().numDocs());
ZimbraTopDocs result = searcher.search(new TermQuery(new Term(LuceneFields.L_CONTACT_DATA, "@zimbra.com")), 100);
Assert.assertNotNull("searcher.search result object - searching for '@zimbra.com'", result);
ZimbraLog.test.debug("Result for search for '@zimbra.com'\n" + result.toString());
Assert.assertEquals("Total hits after 2 adds", 2, result.getTotalHits());
searcher.close();
indexer = index.openIndexer();
indexer.deleteDocument(Collections.singletonList(contact1.getId()));
indexer.close();
searcher = index.openSearcher();
Assert.assertEquals("numDocs after 2 adds/1 del", 1, searcher.getIndexReader().numDocs());
result = searcher.search(new TermQuery(new Term(LuceneFields.L_CONTACT_DATA, "@zimbra.com")), 100);
Assert.assertNotNull("searcher.search result object after 2 adds/1 del", result);
ZimbraLog.test.debug("Result for search for '@zimbra.com'\n" + result.toString());
Assert.assertEquals("Total hits after 2 adds/1 del", 1, result.getTotalHits());
searcher.close();
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class AbstractIndexStoreTest method booleanQuery.
@Test
public void booleanQuery() throws Exception {
ZimbraLog.test.debug("--->TEST booleanQuery");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Contact contact = createContact(mbox, "First", "Last", "f.last@zimbra.com", "Software Development Engineer");
createContact(mbox, "Given", "Surname", "GiV.SurN@zimbra.com");
// Make sure all indexing has been done
mbox.index.indexDeferredItems();
IndexStore index = mbox.index.getIndexStore();
ZimbraIndexSearcher searcher = index.openSearcher();
// This seems to be the supported way of enabling leading wildcard queries
QueryParser queryParser = new QueryParser(LuceneIndex.VERSION, LuceneFields.L_CONTACT_DATA, new StandardAnalyzer(LuceneIndex.VERSION));
queryParser.setAllowLeadingWildcard(true);
Query wquery = queryParser.parse("*irst");
Query tquery = new TermQuery(new Term(LuceneFields.L_CONTACT_DATA, "absent"));
Query tquery2 = new TermQuery(new Term(LuceneFields.L_CONTACT_DATA, "Last"));
BooleanQuery bquery = new BooleanQuery();
bquery.add(wquery, Occur.MUST);
bquery.add(tquery, Occur.MUST_NOT);
bquery.add(tquery2, Occur.SHOULD);
ZimbraTopDocs result = searcher.search(bquery, 100);
Assert.assertNotNull("searcher.search result object", result);
ZimbraLog.test.debug("Result for search [hits=%d]:%s", result.getTotalHits(), result.toString());
Assert.assertEquals("Number of hits", 1, result.getTotalHits());
String expected1Id = String.valueOf(contact.getId());
String match1Id = searcher.doc(result.getScoreDoc(0).getDocumentID()).get(LuceneFields.L_MAILBOX_BLOB_ID);
Assert.assertEquals("Mailbox Blob ID of match", expected1Id, match1Id);
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class AbstractIndexStoreTest method termQuery.
@Test
public void termQuery() throws Exception {
ZimbraLog.test.debug("--->TEST termQuery");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Contact contact = createContact(mbox, "First", "Last", "test@zimbra.com");
createContact(mbox, "a", "bc", "abc@zimbra.com");
createContact(mbox, "j", "k", "j.k@zimbra.com");
createContact(mbox, "Matilda", "Higgs-Bozon", "matilda.higgs.bozon@zimbra.com");
mbox.index.indexDeferredItems();
// Stick with just one IndexStore - the one cached in Mailbox:
// IndexStore index = IndexStore.getFactory().getIndexStore(mbox);
IndexStore index = mbox.index.getIndexStore();
ZimbraIndexSearcher searcher = index.openSearcher();
ZimbraTopDocs result = searcher.search(new TermQuery(new Term(LuceneFields.L_CONTACT_DATA, "none@zimbra.com")), 100);
Assert.assertNotNull("searcher.search result object - searching for none@zimbra.com", result);
ZimbraLog.test.debug("Result for search for 'none@zimbra.com'\n" + result.toString());
Assert.assertEquals("Number of hits searching for none@zimbra.com", 0, result.getTotalHits());
result = searcher.search(new TermQuery(new Term(LuceneFields.L_CONTACT_DATA, "test@zimbra.com")), 100);
Assert.assertNotNull("searcher.search result object - searching for test@zimbra.com", result);
ZimbraLog.test.debug("Result for search for 'test@zimbra.com'\n" + result.toString());
Assert.assertEquals("Number of hits searching for test@zimbra.com", 1, result.getTotalHits());
Assert.assertEquals(String.valueOf(contact.getId()), getBlobIdForResultDoc(searcher, result, 0));
Assert.assertEquals(4, searcher.getIndexReader().numDocs());
searcher.close();
}
use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.
the class AbstractIndexStoreTest method leadingWildcardQuery.
@Test
public void leadingWildcardQuery() throws Exception {
ZimbraLog.test.debug("--->TEST leadingWildcardQuery");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Contact contact = createContact(mbox, "First", "Last", "f.last@zimbra.com", "Leading Wildcard");
createContact(mbox, "Grand", "Piano", "grand@vmware.com");
// Make sure all indexing has been done
mbox.index.indexDeferredItems();
IndexStore index = mbox.index.getIndexStore();
ZimbraIndexSearcher searcher = index.openSearcher();
// This seems to be the supported way of enabling leading wildcard queries for Lucene
QueryParser queryParser = new QueryParser(LuceneIndex.VERSION, LuceneFields.L_CONTACT_DATA, new StandardAnalyzer(LuceneIndex.VERSION));
queryParser.setAllowLeadingWildcard(true);
Query query = queryParser.parse("*irst");
ZimbraTopDocs result = searcher.search(query, 100);
Assert.assertNotNull("searcher.search result object - searching for *irst", result);
ZimbraLog.test.debug("Result for search for '*irst'\n" + result.toString());
Assert.assertEquals("Number of hits searching for *irst", 1, result.getTotalHits());
String expected1Id = String.valueOf(contact.getId());
String match1Id = searcher.doc(result.getScoreDoc(0).getDocumentID()).get(LuceneFields.L_MAILBOX_BLOB_ID);
Assert.assertEquals("Mailbox Blob ID of match", expected1Id, match1Id);
}
Aggregations