fix: Entries without Tags are now searchable

This commit is contained in:
Jann Stute
2024-11-28 00:07:31 +01:00
parent de08849faa
commit 06761a594b
2 changed files with 5 additions and 9 deletions

View File

@@ -420,8 +420,8 @@ class Library:
if search.ast:
statement = (
statement.join(Entry.tag_box_fields)
.join(TagBoxField.tags)
statement.outerjoin(Entry.tag_box_fields)
.outerjoin(TagBoxField.tags)
.where(SQLBoolExpressionBuilder().visit(search.ast))
)
elif search.tag:

View File

@@ -29,20 +29,16 @@ class SQLBoolExpressionBuilder(BaseVisitor):
elif node.type == ConstraintType.TagID:
return Tag.id == int(node.value)
elif node.type == ConstraintType.Path:
return Entry.path.ilike(node.value.replace("*", "%")) # TODO TSQLANG this is broken
return Entry.path.ilike(node.value.replace("*", "%"))
elif node.type == ConstraintType.MediaType:
extensions: set[str] = set[str]()
for media_cat in MediaCategories.ALL_CATEGORIES:
if node.value == media_cat.name:
extensions = extensions | media_cat.extensions
break
return Entry.suffix.in_(
map(lambda x: x.replace(".", ""), extensions)
) # TODO audio doesn't work on mp3 files (might be my library)
return Entry.suffix.in_(map(lambda x: x.replace(".", ""), extensions))
elif node.type == ConstraintType.FileType:
return Entry.suffix.ilike(
node.value
) # TODO TSQLANG this is broken for mp3, but works for png (might be my library)
return Entry.suffix.ilike(node.value)
raise NotImplementedError("This type of constraint is not implemented yet")