Prepare searchin on date range

This commit is contained in:
M66B 2020-04-10 11:51:50 +02:00
parent 4ef64fea56
commit 88b3c684eb
3 changed files with 29 additions and 5 deletions

View File

@ -44,6 +44,7 @@ import java.io.Serializable;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -60,9 +61,11 @@ import javax.mail.UIDFolder;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.search.AndTerm; import javax.mail.search.AndTerm;
import javax.mail.search.BodyTerm; import javax.mail.search.BodyTerm;
import javax.mail.search.ComparisonTerm;
import javax.mail.search.FlagTerm; import javax.mail.search.FlagTerm;
import javax.mail.search.FromStringTerm; import javax.mail.search.FromStringTerm;
import javax.mail.search.OrTerm; import javax.mail.search.OrTerm;
import javax.mail.search.ReceivedDateTerm;
import javax.mail.search.RecipientStringTerm; import javax.mail.search.RecipientStringTerm;
import javax.mail.search.SearchTerm; import javax.mail.search.SearchTerm;
import javax.mail.search.SubjectTerm; import javax.mail.search.SubjectTerm;
@ -195,7 +198,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (fts && pro && criteria.isQueryOnly()) { if (fts && pro && criteria.isQueryOnly()) {
if (state.ids == null) { if (state.ids == null) {
SQLiteDatabase sdb = FtsDbHelper.getInstance(context); SQLiteDatabase sdb = FtsDbHelper.getInstance(context);
state.ids = FtsDbHelper.match(sdb, account, folder, criteria.query); state.ids = FtsDbHelper.match(sdb, account, folder, criteria);
} }
try { try {
@ -228,6 +231,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
criteria.with_hidden, criteria.with_hidden,
criteria.with_encrypted, criteria.with_encrypted,
criteria.with_attachments, criteria.with_attachments,
criteria.from,
criteria.to,
SEARCH_LIMIT, state.offset); SEARCH_LIMIT, state.offset);
Log.i("Boundary device folder=" + folder + Log.i("Boundary device folder=" + folder +
" criteria=" + criteria + " criteria=" + criteria +
@ -421,6 +426,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
state.ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) state.ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED))
and.add(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true)); and.add(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true));
if (criteria.from != null)
and.add(new ReceivedDateTerm(ComparisonTerm.GT, new Date(criteria.from)));
if (criteria.to != null)
and.add(new ReceivedDateTerm(ComparisonTerm.LT, new Date(criteria.to)));
SearchTerm term = null; SearchTerm term = null;
if (or.size() > 0) if (or.size() > 0)
@ -608,13 +618,15 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
boolean in_senders = true; boolean in_senders = true;
boolean in_receipients = true; boolean in_receipients = true;
boolean in_subject = true; boolean in_subject = true;
boolean in_keywords = true; boolean in_keywords = false;
boolean in_message = true; boolean in_message = true;
boolean with_unseen; boolean with_unseen;
boolean with_flagged; boolean with_flagged;
boolean with_hidden; boolean with_hidden;
boolean with_encrypted; boolean with_encrypted;
boolean with_attachments; boolean with_attachments;
Long from = null;
Long to = null;
SearchCriteria() { SearchCriteria() {
} }
@ -672,7 +684,9 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
this.with_flagged == other.with_flagged && this.with_flagged == other.with_flagged &&
this.with_hidden == other.with_hidden && this.with_hidden == other.with_hidden &&
this.with_encrypted == other.with_encrypted && this.with_encrypted == other.with_encrypted &&
this.with_attachments == other.with_attachments); this.with_attachments == other.with_attachments &&
Objects.equals(this.from, other.from) &&
Objects.equals(this.to, other.to));
} else } else
return false; return false;
} }

View File

@ -296,11 +296,14 @@ public interface DaoMessage {
" AND (NOT :hidden OR NOT ui_snoozed IS NULL)" + " AND (NOT :hidden OR NOT ui_snoozed IS NULL)" +
" AND (NOT :encrypted OR ui_encrypt > 0)" + " AND (NOT :encrypted OR ui_encrypt > 0)" +
" AND (NOT :attachments OR attachments > 0)" + " AND (NOT :attachments OR attachments > 0)" +
" AND (:from IS NULL OR received > :from)" +
" AND (:to IS NULL OR received < :to)" +
" ORDER BY received DESC" + " ORDER BY received DESC" +
" LIMIT :limit OFFSET :offset") " LIMIT :limit OFFSET :offset")
List<TupleMatch> matchMessages( List<TupleMatch> matchMessages(
Long account, Long folder, String find, Long account, Long folder, String find,
boolean unseen, boolean flagged, boolean hidden, boolean encrypted, boolean attachments, boolean unseen, boolean flagged, boolean hidden, boolean encrypted, boolean attachments,
Long from, Long to,
int limit, int offset); int limit, int offset);
@Query("SELECT id" + @Query("SELECT id" +

View File

@ -107,9 +107,12 @@ public class FtsDbHelper extends SQLiteOpenHelper {
db.delete("message", "rowid = ?", new Object[]{id}); db.delete("message", "rowid = ?", new Object[]{id});
} }
static List<Long> match(SQLiteDatabase db, Long account, Long folder, String query) { static List<Long> match(
SQLiteDatabase db,
Long account, Long folder,
BoundaryCallbackMessages.SearchCriteria criteria) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (String or : query.split(",")) { for (String or : criteria.query.split(",")) {
if (sb.length() > 0) if (sb.length() > 0)
sb.append(" OR "); sb.append(" OR ");
@ -137,6 +140,10 @@ public class FtsDbHelper extends SQLiteOpenHelper {
select += "account = " + account + " AND "; select += "account = " + account + " AND ";
if (folder != null) if (folder != null)
select += "folder = " + folder + " AND "; select += "folder = " + folder + " AND ";
if (criteria.from != null)
select += "time > " + criteria.from + " AND ";
if (criteria.to != null)
select += "time < " + criteria.to + " AND ";
Log.i("FTS select=" + select + " search=" + search); Log.i("FTS select=" + select + " search=" + search);
List<Long> result = new ArrayList<>(); List<Long> result = new ArrayList<>();