feat(filters): the rule builder — composed engines over the field registry (faceted plan Phase 9)
- Field registry (services/filter_registry.go): ~55 typed fields — every book column, file/lifecycle facts, the three HOLDING STRUCTURES (library, collections with excluded-aware membership, series with FULL primary+alternate_info membership), and the whole user-relative class (status, progress, last read, my rating, review, notes/highlights presence, note/highlight text, time spent, pages read, collections, added by) reading the VIEWER's rows. Operators are typed constants; negation is an operator. - Composed engines (services/filter_query.go): one Go clause builder over raw pgx feeds the search (identical SearchMediaItemsUnifiedRow shape), the field-aware suggestions, and a true-COUNT live count. Mandatory WHERE head everywhere (family lens + integrity facts). Values are always bound parameters — no user string reaches a field/operator position, ever. - Wire: the qf JSON param (validated strictly — unknown fields/operators/malformed values are 400); qf wins over flat params on hand-crafted URLs; flat deep links keep working unchanged. - Endpoints: GET /api/media-items/filter-count (live count); field-values autocomplete upgraded in place — any registry field key, qf binds the OTHER rules (symmetric under-filter suggestions, zero-match values never offered); classic six without a tree keep their static pinned contract. - UI: the drawer becomes the rule builder — the ONLY filter UI (templ markup, Alpine tree state, sanctioned island; grouped field menus, operator menus with red negations, field-aware value menus, live count, chips per rule with red negations, URL rehydration, smart serialization flat-when-simple else qf). - Tests: composed semantics (AND/OR/negation/nesting/enums/bools/ numbers/dates/empty), every user-relative field class with the my-data weld (two readers, different worlds), note-text substring pin (catharsis ≠ Carthage), family lens (hidden libraries nowhere, 403s), suggestion-under-rules exactness, qf validation + precedence, flat-vs-tree equivalence; registry completeness unit test.
This commit is contained in:
1 parent
ebb7f4a5b0
commit
4ee24e7152
18 files changed
+3788
-376
No files matched your search
@@ -29,6 +29,9 @@ func registerSearchRoutes(cfg *Config) {
|
||||
// Facet-value listings for the filter panel (faceted-navigation
|
||||
// Batch C): /api/media-items/facets?facet=X&library_id=...
|
||||
protected.GET("/media-items/facets", cfg.MediaHandler.GetFacets)
|
||||
// Rule-builder live count (faceted plan Phase 9): the composed
|
||||
// tree's true match count (COUNT(*)), rules + library scope.
|
||||
protected.GET("/media-items/filter-count", cfg.MediaHandler.FilterCount)
|
||||
protected.POST("/sync/books/query", cfg.MatchingHandler.QueryBooks)
|
||||
}
|
||||
|
||||
@@ -45,6 +48,12 @@ func handleSearchHTML(c *echo.Context, cfg *Config) error {
|
||||
// parser fixes that too.)
|
||||
params := handlers.ParseMediaSearchParams(c)
|
||||
params.UserID = user.ID
|
||||
|
||||
// Filter rule builder: a malformed qf is a 400, never a silently
|
||||
// ignored token.
|
||||
if params.FilterParseErr != "" {
|
||||
return c.HTML(http.StatusBadRequest, `<div style="color: red;">Invalid filter</div>`)
|
||||
}
|
||||
limit := params.Limit
|
||||
offset := params.Offset
|
||||
libraryID := c.QueryParam("library_id")
|
||||
|
||||
Reference in new issue
Block a user