Add support for sorting by various fields

This commit is contained in:
2026-03-21 01:44:17 +01:00
parent 6b65d9cd15
commit 167b37f471
5 changed files with 180 additions and 42 deletions

View File

@@ -329,33 +329,54 @@ class TestBookSearchCommand:
[
# String field filters
("title:Hobbit", "", ["The Hobbit"]),
("author:Tolkien", "", ["The Hobbit", "The Fellowship"]),
("genre:Fantasy", "", ["The Hobbit", "The Fellowship"]),
("owner:alice", "", ["The Hobbit", "The Fellowship", "Dune"]),
("place:home", "", ["The Hobbit", "Programming Book"]),
("bookshelf:fantasy", "", ["The Hobbit", "The Fellowship"]),
("author:Tolkien", "", ["The Fellowship", "The Hobbit"]),
("genre:Fantasy", "", ["The Fellowship", "The Hobbit"]),
("owner:alice", "", ["Dune", "The Fellowship", "The Hobbit"]),
("place:home", "", ["Programming Book", "The Hobbit"]),
("bookshelf:fantasy", "", ["The Fellowship", "The Hobbit"]),
# Numeric field filters
("rating>=4", "", ["The Hobbit", "Programming Book"]),
("rating>=4", "", ["Programming Book", "The Hobbit"]),
("rating=3", "", ["Dune"]),
("shelf>1", "", ["The Fellowship", "Programming Book"]),
("year>=1954", "", ["The Fellowship", "Dune", "Programming Book"]),
("shelf>1", "", ["Programming Book", "The Fellowship"]),
("year>=1954", "", ["Programming Book", "Dune", "The Fellowship"]),
# Date field filters
(
"added>=2026-03-15",
"",
["The Hobbit", "The Fellowship", "Dune", "Programming Book"],
["Programming Book", "Dune", "The Fellowship", "The Hobbit"],
),
("bought<2026-01-01", "", ["Programming Book"]),
# Negation
("-genre:Fantasy", "", ["Dune", "Programming Book"]),
("-owner:bob", "", ["The Hobbit", "The Fellowship", "Dune"]),
("-genre:Fantasy", "", ["Programming Book", "Dune"]),
("-owner:bob", "", ["Dune", "The Fellowship", "The Hobbit"]),
# Complex query with multiple filters
("-genre:Fantasy owner:alice", "", ["Dune"]),
# User-specific queries
("rating>=4", "alice", ["The Hobbit"]),
("is:reading", "alice", ["The Fellowship"]),
("is:read", "alice", ["The Hobbit", "Dune"]),
("is:read", "alice", ["Dune", "The Hobbit"]),
("is:wished", "alice", ["Programming Book"]),
# Sorting
(
"sort:added-desc",
"",
["Programming Book", "Dune", "The Fellowship", "The Hobbit"],
),
(
"sort:added-asc",
"",
["The Hobbit", "The Fellowship", "Dune", "Programming Book"],
),
(
"sort:read-desc",
"alice",
["Dune", "The Hobbit", "Programming Book", "The Fellowship"],
),
(
"sort:owner-asc",
"",
["Dune", "The Fellowship", "The Hobbit", "Programming Book"],
),
],
)
def test_book_search_advanced_queries(
@@ -383,7 +404,7 @@ class TestBookSearchCommand:
actual_titles = [book["title"] for book in search_results]
# Verify expected titles are present (order doesn't matter)
assert set(expected_titles) == set(actual_titles), (
assert expected_titles == actual_titles, (
f"Query '{query}' expected {expected_titles}, got {actual_titles}"
)