use of com.zimbra.cs.index.ZimbraIndexSearcher in project zm-mailbox by Zimbra.
the class MailboxIndex method getAttachmentTypes.
/**
* Returns all attachment types from the index.
*
* @param regex matching pattern or null to match everything
* @return {@link BrowseTerm}s which correspond to all of the attachment types in the index
*/
public List<BrowseTerm> getAttachmentTypes(String regex) throws IOException, ServiceException {
Pattern pattern = Strings.isNullOrEmpty(regex) ? null : Pattern.compile(regex);
List<BrowseTerm> result = new ArrayList<BrowseTerm>();
ZimbraIndexSearcher searcher = indexStore.openSearcher();
TermFieldEnumeration values = null;
try {
values = searcher.getIndexReader().getTermsForField(LuceneFields.L_ATTACHMENTS, "");
while (values.hasMoreElements()) {
BrowseTerm term = values.nextElement();
if (pattern == null || AccessBoundedRegex.matches(term.getText(), pattern, MAX_REGEX_ACCESSES)) {
result.add(term);
}
}
} finally {
Closeables.closeQuietly(values);
Closeables.closeQuietly(searcher);
}
return result;
}
use of com.zimbra.cs.index.ZimbraIndexSearcher in project zm-mailbox by Zimbra.
the class MailboxIndex method getDomains.
/**
* Returns all domain names from the index.
*
* @param field Lucene field name (e.g. LuceneFields.L_H_CC)
* @param regex matching pattern or null to match everything
* @return {@link BrowseTerm}s which correspond to all of the domain terms stored in a given field
*/
public List<BrowseTerm> getDomains(String field, String regex) throws IOException, ServiceException {
Pattern pattern = Strings.isNullOrEmpty(regex) ? null : Pattern.compile(regex.startsWith("@") ? regex : "@" + regex);
List<BrowseTerm> result = new ArrayList<BrowseTerm>();
ZimbraIndexSearcher searcher = indexStore.openSearcher();
TermFieldEnumeration values = null;
try {
values = searcher.getIndexReader().getTermsForField(field, "");
while (values.hasMoreElements()) {
BrowseTerm term = values.nextElement();
if (term == null) {
break;
}
String text = term.getText();
// Domains are tokenized with '@' prefix. Exclude partial domain tokens.
if (text.startsWith("@") && text.contains(".")) {
if (pattern == null || AccessBoundedRegex.matches(text, pattern, MAX_REGEX_ACCESSES)) {
result.add(new BrowseTerm(text.substring(1), term.getFreq()));
}
}
}
} finally {
Closeables.closeQuietly(values);
Closeables.closeQuietly(searcher);
}
return result;
}
use of com.zimbra.cs.index.ZimbraIndexSearcher in project zm-mailbox by Zimbra.
the class MailboxIndex method existsInContacts.
/**
* Returns true if any of the specified email addresses exists in contacts, otherwise false.
*/
public boolean existsInContacts(Collection<InternetAddress> addrs) throws IOException {
Set<MailItem.Type> types = EnumSet.of(MailItem.Type.CONTACT);
if (getDeferredCount(types) > 0) {
try {
indexDeferredItems(types, new BatchStatus(), false);
} catch (ServiceException e) {
ZimbraLog.index.error("Failed to index deferred items", e);
}
}
ZimbraIndexSearcher searcher = indexStore.openSearcher();
try {
for (InternetAddress addr : addrs) {
if (!Strings.isNullOrEmpty(addr.getAddress())) {
String lcAddr = addr.getAddress().toLowerCase();
TermFieldEnumeration values = null;
try {
values = searcher.getIndexReader().getTermsForField(LuceneFields.L_CONTACT_DATA, lcAddr);
if (values.hasMoreElements()) {
BrowseTerm term = values.nextElement();
if (term != null && lcAddr.equals(term.getText())) {
ZimbraLog.index.debug("Contact = %s present in indexed items", lcAddr);
return true;
}
}
} finally {
Closeables.closeQuietly(values);
}
}
}
return false;
} finally {
Closeables.closeQuietly(searcher);
}
}
use of com.zimbra.cs.index.ZimbraIndexSearcher in project zm-mailbox by Zimbra.
the class MailboxIndex method getObjects.
/**
* Returns all objects (e.g. PO, etc) from the index.
*
* @param regex matching pattern or null to match everything
* @return {@link BrowseTerm}s which correspond to all of the objects in the index
*/
public List<BrowseTerm> getObjects(String regex) throws IOException, ServiceException {
Pattern pattern = Strings.isNullOrEmpty(regex) ? null : Pattern.compile(regex);
List<BrowseTerm> result = new ArrayList<BrowseTerm>();
ZimbraIndexSearcher searcher = indexStore.openSearcher();
TermFieldEnumeration values = null;
try {
values = searcher.getIndexReader().getTermsForField(LuceneFields.L_OBJECTS, "");
while (values.hasMoreElements()) {
BrowseTerm term = values.nextElement();
if (term == null) {
break;
}
if (pattern == null || AccessBoundedRegex.matches(term.getText(), pattern, MAX_REGEX_ACCESSES)) {
result.add(term);
}
}
} finally {
Closeables.closeQuietly(values);
Closeables.closeQuietly(searcher);
}
return result;
}
Aggregations