fix(negative-prompt): fix incorrect handling of special flags; tweak negative prompt

related to comment https://github.com/TagStudioDev/TagStudio/pull/284#issuecomment-2227466476
This commit is contained in:
lunaro-4 2024-07-26 22:57:39 +03:00
parent e9ed224dde
commit d03d2a7f1b
3 changed files with 23 additions and 16 deletions

View file

@ -1375,8 +1375,13 @@ class Library:
negative_flags.append(negative_flag)
flags.remove(flag)
if negative_flags:
query_part["EMPTY"] = negative_flags
query_part[unbound_keyname] = flags
query_part[KeyNameConstants.EMPTY_FIELD_QUERY_KEYNAME] = (
negative_flags
)
if flags:
query_part[unbound_keyname] = flags
else:
query_part.pop(unbound_keyname)
meta_list.append(query_part)
logging.info(f"Parsed values: {meta_list}")
@ -2194,10 +2199,10 @@ class SpecialFlag:
only_missing: bool
def __init__(self, query: str):
self.only_no_author: bool = "no author" in query or "no artist" in query
self.only_untagged: bool = "untagged" in query or "no tags" in query
self.only_empty: bool = "empty" in query or "no fields" in query
self.only_missing: bool = "missing" in query or "no file" in query
self.only_no_author: bool = "noauthor" in query or "noartist" in query
self.only_untagged: bool = "untagged" in query or "notags" in query
self.only_empty: bool = "empty" in query or "nofields" in query
self.only_missing: bool = "missing" in query or "nofile" in query
class Filter:

View file

@ -10,7 +10,7 @@ def test_open_library(test_library, snapshot_json):
[
("First",),
("Second",),
("--nomatch--",),
("/--nomatch--/",),
],
)
def test_library_search(test_library, query, snapshot_json):

View file

@ -71,6 +71,7 @@ decomposition_cases: list[tuple] = [
[{key_unbound: ["tag1"], key_empty: ["description"]}, {"description": "desc"}],
),
("; no author", [{key_unbound: ["no", "author"]}]),
("-author", [{key_empty: ["author"]}]),
("description: Foo", [{"description": "foo"}]),
]
@ -99,15 +100,16 @@ populate_tags_cases: list[tuple] = [
# no_author, untagged, empty, missing
special_flag_cases: list[tuple] = [
("no author untagged", (True, True, False, False)),
("empty no file", (False, False, True, True)),
("missing untagged no artist", (True, True, False, True)),
("noauthoruntagged", (True, True, False, False)),
("emptynofile", (False, False, True, True)),
("missinguntaggednoartist", (True, True, False, True)),
("noartist", (True, False, False, False)),
]
add_entries_from_special_cases: list[tuple] = [
(test_entry_one, "no author", False),
(test_entry_one, "noauthor", False),
(test_entry_two, "empty", True),
(test_entry_three, "no author", True),
(test_entry_three, "noauthor", True),
(test_entry_four, "untagged", True),
]
@ -119,12 +121,12 @@ required_fields_empty_cases: list[tuple] = [
]
filter_case_one: tuple = (
[{key_unbound: "no author", "description": "des"}],
[{key_unbound: ["no", "author"], "description": "des"}],
SearchMode.OR,
[(ItemType.ENTRY, 2), (ItemType.ENTRY, 5)],
)
filter_case_two: tuple = (
[{key_unbound: "no tags"}, {"description": "des"}],
[{key_unbound: ["no", "tags"]}, {"description": "des"}],
SearchMode.OR,
[
(ItemType.ENTRY, 1),
@ -140,13 +142,13 @@ filter_case_three: tuple = (
[],
)
filter_case_four: tuple = (
[{"tag_id": "1001", key_unbound: "no author"}],
[{"tag_id": "1001", key_unbound: ["no", "author"]}],
SearchMode.OR,
[(ItemType.ENTRY, 2)],
)
filter_case_five: tuple = (
[{"tag_id": "1000"}, {key_unbound: "no author"}],
[{"tag_id": "1000"}, {key_unbound: ["no", "author"]}],
SearchMode.OR,
[
(ItemType.ENTRY, 0),