diff --git a/tagstudio/src/core/library/alchemy/library.py b/tagstudio/src/core/library/alchemy/library.py index 0aed7ce44..3a1a7678c 100644 --- a/tagstudio/src/core/library/alchemy/library.py +++ b/tagstudio/src/core/library/alchemy/library.py @@ -438,7 +438,8 @@ def search_library( ) ) elif search.path: - statement = statement.where(Entry.path.ilike(f"%{search.path}%")) + search_str = str(search.path).replace("*", "%") + statement = statement.where(Entry.path.ilike(search_str)) elif search.filetype: statement = statement.where(Entry.suffix.ilike(f"{search.filetype}")) elif search.mediatype: diff --git a/tagstudio/tests/qt/test_qt_driver.py b/tagstudio/tests/qt/test_qt_driver.py index e032b3fb7..d405030c6 100644 --- a/tagstudio/tests/qt/test_qt_driver.py +++ b/tagstudio/tests/qt/test_qt_driver.py @@ -94,7 +94,7 @@ def test_library_state_update(qt_driver): assert list(entry.tags)[0].name == "foo" # When state property is changed, previous one is overwritten - state = FilterState(path="bar.md") + state = FilterState(path="*bar.md") qt_driver.filter_items(state) assert len(qt_driver.frame_content) == 1 entry = qt_driver.frame_content[0] diff --git a/tagstudio/tests/test_library.py b/tagstudio/tests/test_library.py index db28a72a3..24e4d9b90 100644 --- a/tagstudio/tests/test_library.py +++ b/tagstudio/tests/test_library.py @@ -3,7 +3,7 @@ import pytest from src.core.enums import DefaultEnum, LibraryPrefs -from src.core.library.alchemy import Entry +from src.core.library.alchemy import Entry, Library from src.core.library.alchemy.enums import FilterState from src.core.library.alchemy.fields import TextField, _FieldID @@ -403,6 +403,24 @@ class TestPrefs(DefaultEnum): assert TestPrefs.BAR.value +def test_path_search_glob_after(library: Library): + results = library.search_library(FilterState(path="foo*")) + assert results.total_count == 1 + assert len(results.items) == 1 + + +def test_path_search_glob_in_front(library: Library): + results = library.search_library(FilterState(path="*bar.md")) + assert results.total_count == 1 + assert len(results.items) == 1 + + +def test_path_search_glob_both_sides(library: Library): + results = library.search_library(FilterState(path="*one/two*")) + assert results.total_count == 1 + assert len(results.items) == 1 + + @pytest.mark.parametrize(["filetype", "num_of_filetype"], [("md", 1), ("txt", 1), ("png", 0)]) def test_filetype_search(library, filetype, num_of_filetype): results = library.search_library(FilterState(filetype=filetype))