diff --git a/lib/Db/MessageMapper.php b/lib/Db/MessageMapper.php index 4aece97fd3..0374992bdc 100644 --- a/lib/Db/MessageMapper.php +++ b/lib/Db/MessageMapper.php @@ -928,9 +928,10 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, string $sor } // createParameter if ($uids !== null) { - // In the case of body+subject search we need a combination of both results, - // thus the orWhere in every other case andWhere should do the job. - if (!empty($query->getSubjects())) { + // In anyof mode or when subjects are also searched, body results must be + // OR'd with other criteria so a match in any one field is sufficient. + // In allof mode without subjects, AND is correct: all criteria must match. + if (!empty($query->getSubjects()) || $query->getMatch() === 'anyof') { $textOrs[] = $qb->expr()->in('m.uid', $qb->createParameter('uids')); } else { $select->andWhere( diff --git a/lib/Service/Search/MailSearch.php b/lib/Service/Search/MailSearch.php index 16f8ada442..5c9279b9aa 100644 --- a/lib/Service/Search/MailSearch.php +++ b/lib/Service/Search/MailSearch.php @@ -150,7 +150,7 @@ public function findMessagesGlobally( * @throws ServiceException */ private function getIdsLocally(Account $account, Mailbox $mailbox, SearchQuery $query, string $sortOrder, ?int $limit): array { - if (empty($query->getBodies())) { + if (empty($query->getBodies()) || !$account->getMailAccount()->getSearchBody()) { return $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, $limit); } @@ -159,6 +159,11 @@ private function getIdsLocally(Account $account, Mailbox $mailbox, SearchQuery $ $mailbox, $query ); + + if (empty($fromImap)) { + return $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, $limit); + } + return $this->messageMapper->findIdsByQuery($mailbox, $query, $sortOrder, $limit, $fromImap); } diff --git a/src/components/SearchMessages.vue b/src/components/SearchMessages.vue index c5b8a8cbff..eb37d9f0fe 100644 --- a/src/components/SearchMessages.vue +++ b/src/components/SearchMessages.vue @@ -484,7 +484,7 @@ export default { } this.match = 'anyof' - this.searchInMessageBody = this.searchBody ? this.query : null + this.searchInMessageBody = this.query this.searchInSubject = this.query this.searchInFrom = [{ email: this.query, label: this.query }] this.searchInTo = [{ email: this.query, label: this.query }]