Skip to content

Commit 290866f

Browse files
author
cat101
committed
fix: handle NULL title when negating any_text / title: search
Wrap the title LIKE clause in a Brackets predicate that also matches 'media.metadata.title IS NULL' when the query is negated. Without this, photos with no title (the common case) are excluded from negated any_text results because NULL NOT LIKE 'x' evaluates to NULL (three-valued logic), which fails the AND-chain that negation builds. Mirrors the existing pattern used for array fields (keywords/persons) at matchArrayField — text-typed sparse fields need the same treatment.
1 parent 373586e commit 290866f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/backend/model/database/SearchManager.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,9 +1025,19 @@ export class SearchManager {
10251025
(query.type === SearchQueryTypes.any_text && !directoryOnly) ||
10261026
query.type === SearchQueryTypes.title
10271027
) {
1028+
// title is sparse: most photos have no title set. When negating, treat
1029+
// NULL as a match so a `-title:X` (or negated any_text) doesn't filter
1030+
// out untitled photos due to NULL NOT LIKE = NULL three-valued logic.
10281031
q[whereFN](
1029-
`media.metadata.title ${LIKE} :text${queryId} COLLATE ${SQL_COLLATE}`,
1030-
textParam
1032+
new Brackets((qbr): void => {
1033+
qbr.where(
1034+
`media.metadata.title ${LIKE} :text${queryId} COLLATE ${SQL_COLLATE}`,
1035+
textParam
1036+
);
1037+
if ((query as TextSearch).negate) {
1038+
qbr.orWhere('media.metadata.title IS NULL');
1039+
}
1040+
})
10311041
);
10321042
}
10331043

0 commit comments

Comments
 (0)