Implicitly add “AND” in search parsing to enable bla is:unread, fix no-results state

This commit is contained in:
Ben Gotow 2017-11-12 21:00:52 +01:00
parent e125f05396
commit a416c4b0fa
4 changed files with 17 additions and 9 deletions

View file

@ -61,6 +61,9 @@ class SearchMailboxPerspective extends MailboxPerspective {
tasksForRemovingItems(threads) {
return TaskFactory.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => {
const account = AccountStore.accountForId(accountId);
if (!account) {
return [];
}
const dest = account.preferredRemovalDestination();
if (dest instanceof Folder) {

View file

@ -41,7 +41,6 @@ class SearchQuerySubscription extends MutableQuerySubscription {
this._searchStartedAt = Date.now();
this.performLocalSearch();
this.performRemoteSearch();
this.performExtensionSearch();
}
@ -50,6 +49,7 @@ class SearchQuerySubscription extends MutableQuerySubscription {
if (this._accountIds.length === 1) {
dbQuery = dbQuery.where({ accountId: this._accountIds[0] });
}
try {
const parsedQuery = SearchQueryParser.parse(this._searchQuery);
dbQuery = dbQuery.structuredSearch(parsedQuery);
@ -60,9 +60,8 @@ class SearchQuerySubscription extends MutableQuerySubscription {
dbQuery = dbQuery.order(Thread.attributes.lastMessageReceivedTimestamp.descending()).limit(100);
dbQuery.then(results => {
if (results.length > 0) {
this.replaceQuery(dbQuery);
}
SearchActions.searchCompleted();
this.replaceQuery(dbQuery);
});
}
@ -87,9 +86,6 @@ class SearchQuerySubscription extends MutableQuerySubscription {
// search message bodies, so local search is pretty much
// good enough for v1. Come back and implement this soon!
//
setTimeout(() => {
SearchActions.searchCompleted();
}, 400);
}
performExtensionSearch() {

View file

@ -85,6 +85,9 @@ class AndQueryExpression extends QueryExpression {
}
_computeIsMatchCompatible() {
if (!this.e1 || !this.e2) {
return false;
}
return this.e1.isMatchCompatible() && this.e2.isMatchCompatible();
}
@ -108,6 +111,9 @@ class OrQueryExpression extends QueryExpression {
}
_computeIsMatchCompatible() {
if (!this.e1 || !this.e2) {
return false;
}
return this.e1.isMatchCompatible() && this.e2.isMatchCompatible();
}

View file

@ -301,10 +301,13 @@ const parseAndQuery = text => {
if (tok === null) {
return [lhs, afterLhs];
}
if (tok.s.toUpperCase() !== 'AND') {
// Ben Edit: within a search group eg (test is:unread), we assume tokens (eg is:)
// are separated by an implicit AND when one is not present. The only things that
// break us out of the AND query are a close paren or an explicit OR token.
if (tok.s.toUpperCase() === 'OR' || tok.s.toUpperCase() === ')') {
return [lhs, afterLhs];
}
const [rhs, afterRhs] = parseAndQuery(afterAnd);
const [rhs, afterRhs] = parseAndQuery(tok.s.toUpperCase() === 'AND' ? afterAnd : afterLhs);
return [new AndQueryExpression(lhs, rhs), afterRhs];
};