From 50ff8bcce78055d90be7cd1c027e0cf55a7f609e Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 9 Feb 2022 09:39:42 -0500 Subject: [PATCH] Add "random" sort option for Smart Playlists --- model/criteria/criteria_test.go | 6 ++++++ model/criteria/fields.go | 1 + 2 files changed, 7 insertions(+) diff --git a/model/criteria/criteria_test.go b/model/criteria/criteria_test.go index 5f43dc0e1..6ac2eb7c5 100644 --- a/model/criteria/criteria_test.go +++ b/model/criteria/criteria_test.go @@ -81,4 +81,10 @@ var _ = Describe("Criteria", func() { gomega.Expect(string(j)).To(gomega.Equal(jsonObj)) }) + It("allows sort by random", func() { + newObj := goObj + newObj.Sort = "random" + gomega.Expect(newObj.OrderBy()).To(gomega.Equal("random() asc")) + }) + }) diff --git a/model/criteria/fields.go b/model/criteria/fields.go index b14aa5d08..205861f90 100644 --- a/model/criteria/fields.go +++ b/model/criteria/fields.go @@ -43,6 +43,7 @@ var fieldMap = map[string]*mappedField{ "lastplayed": {field: "annotation.play_date"}, "playcount": {field: "COALESCE(annotation.play_count, 0)", order: "annotation.play_count"}, "rating": {field: "COALESCE(annotation.rating, 0)", order: "annotation.rating"}, + "random": {field: "-", order: "random()"}, } type mappedField struct {