fix: implement proper 3-state boolean logic for has_cover filter
Fixed the SearchMediaItemsUnified query to properly handle the has_cover
parameter in three states:
- NULL (not specified): Show all books
- TRUE: Show only books with cover images
- FALSE: Show only books without cover images
Changes:
- Added explicit boolean casting (::bool) to sqlc.narg('has_cover')
to resolve PostgreSQL type inference error (SQLSTATE 42P08)
- Replaced single AND condition with OR'd logic to handle all three
states without mutual exclusion
- Used IS NULL check to detect when parameter is not specified
- Used IS TRUE/IS FALSE to explicitly check boolean states
The previous implementation had mutually exclusive AND conditions that
prevented any records from matching when has_cover was explicitly set
to TRUE or FALSE, causing the filter to block all searches.
This fix resolves the issue where searches were returning 0 results
regardless of other filter parameters when has_cover was included in
the query.
This commit is contained in:
@@ -452,7 +452,11 @@ WHERE COALESCE(lv.is_visible, true) = true
|
||||
(mi.date_published IS NULL AND mi.copyright_year <= sqlc.narg('year_max'))
|
||||
)
|
||||
-- Boolean (exact)
|
||||
AND (sqlc.narg('has_cover') = false OR mi.cover_image_path IS NOT NULL)
|
||||
AND (
|
||||
sqlc.narg('has_cover')::bool IS NULL OR -- Not specified = show all
|
||||
(sqlc.narg('has_cover')::bool IS TRUE AND mi.cover_image_path IS NOT NULL) OR
|
||||
(sqlc.narg('has_cover')::bool IS FALSE AND mi.cover_image_path IS NULL)
|
||||
)
|
||||
-- Search query (fuzzy or exact based on quotes)
|
||||
AND (
|
||||
sqlc.narg('search_query') = '' OR
|
||||
|
||||
Reference in New Issue
Block a user