Skip to content
Open
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
15 changes: 15 additions & 0 deletions core/gallery/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ func (gm GalleryElements[T]) Search(term string) GalleryElements[T] {
return filteredModels
}

// FilterByTag returns only elements that have the specified tag as an exact match
func (gm GalleryElements[T]) FilterByTag(tag string) GalleryElements[T] {
var filtered GalleryElements[T]
tag = strings.ToLower(tag)
for _, m := range gm {
for _, t := range m.GetTags() {
if strings.ToLower(t) == tag {
filtered = append(filtered, m)
break
}
}
}
return filtered
}

func (gm GalleryElements[T]) SortByName(sortOrder string) GalleryElements[T] {
sort.Slice(gm, func(i, j int) bool {
if sortOrder == "asc" {
Expand Down
14 changes: 12 additions & 2 deletions core/http/routes/ui_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model
}
sort.Strings(tags)

if term != "" {
tag := c.QueryParam("tag")

// Filter by tag if provided (exact match)
if tag != "" {
models = gallery.GalleryElements[*gallery.GalleryModel](models).FilterByTag(tag)
} else if term != "" {
models = gallery.GalleryElements[*gallery.GalleryModel](models).Search(term)
}

Expand Down Expand Up @@ -603,7 +608,12 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model
}
sort.Strings(tags)

if term != "" {
tag := c.QueryParam("tag")

// Filter by tag if provided (exact match)
if tag != "" {
backends = gallery.GalleryElements[*gallery.GalleryBackend](backends).FilterByTag(tag)
} else if term != "" {
backends = gallery.GalleryElements[*gallery.GalleryBackend](backends).Search(term)
}

Expand Down
24 changes: 24 additions & 0 deletions gallery.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--- a/core/gallery/gallery.go
+++ b/core/gallery/gallery.go
@@ -83,6 +83,18 @@ func (gm GalleryElements[T]) Search(term string) GalleryElements[T] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you submitted a patch.

return filteredModels
}

+// FilterByTag returns only elements that have the specified tag as an exact match
+func (gm GalleryElements[T]) FilterByTag(tag string) GalleryElements[T] {
+ var filtered GalleryElements[T]
+ tag = strings.ToLower(tag)
+ for _, m := range gm {
+ for _, t := range m.GetTags() {
+ if strings.ToLower(t) == tag {
+ filtered = append(filtered, m)
+ break
+ }
+ }
+ }
+ return filtered
+}
+
func (gm GalleryElements[T]) SortByName(sortOrder string) GalleryElements[T] {
sort.Slice(gm, func(i, j int) bool {
if sortOrder == "asc" {
Loading