Skip to content

feat: make path search use globs #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/tests/qt/test_qt_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 19 additions & 1 deletion tagstudio/tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down