Search in sources :

Example 1 with DatedDocument

use of edu.stanford.muse.index.DatedDocument in project epadd by ePADD.

the class Filter method matches.

public boolean matches(Document d) {
    if (d instanceof DatedDocument) {
        DatedDocument dd = (DatedDocument) d;
        if (!matchesDate(dd))
            return false;
    }
    if (keywords != null && keywords.size() > 0) {
        log.warn("Filtering by keywords during fetch&index is currently disabled");
        Util.softAssert(false, log);
    // String s = d.getContents().toLowerCase();
    // // check for all keywords, if any absent return false
    // for (String keyword: keywords)
    // if (s.indexOf(keyword) < 0)
    // return false;
    }
    // extra checks for email doc
    if (d instanceof EmailDocument) {
        // check if any of the people involved in this message are one of personContacts
        EmailDocument ed = (EmailDocument) d;
        if (personContacts.size() > 0) {
            // if this is the case, we will explicitly apply the filter again, so its ok.
            if (addressBook != null) {
                List<String> list = ed.getAllAddrs();
                Set<Contact> contactsInThisMessage = new LinkedHashSet<>();
                for (String s : list) {
                    Contact c = addressBook.lookupByEmail(s);
                    if (c != null)
                        contactsInThisMessage.add(c);
                }
                contactsInThisMessage.retainAll(personContacts);
                if (contactsInThisMessage.size() == 0)
                    return false;
            }
        }
        if (sentMessagesOnly) {
            if (ownContact != null) {
                String fromEmail = ed.getFromEmailAddress();
                Set<String> ownAddrs = ownContact.getEmails();
                if (!ownAddrs.contains(fromEmail))
                    return false;
            } else {
                log.warn("WARNING: user error: trying to use sent-only option without setting user's own contact info");
            // in this case, we assume a match implicitly because we don't want to filter out all messages
            }
        }
    }
    return true;
}
Also used : EmailDocument(edu.stanford.muse.index.EmailDocument) DatedDocument(edu.stanford.muse.index.DatedDocument) Contact(edu.stanford.muse.AddressBookManager.Contact)

Aggregations

Contact (edu.stanford.muse.AddressBookManager.Contact)1 DatedDocument (edu.stanford.muse.index.DatedDocument)1 EmailDocument (edu.stanford.muse.index.EmailDocument)1