diff --git a/src/main/kotlin/uk/co/neviyn/booru/Controller.kt b/src/main/kotlin/uk/co/neviyn/booru/Controller.kt index 5db5c50..3ec386b 100644 --- a/src/main/kotlin/uk/co/neviyn/booru/Controller.kt +++ b/src/main/kotlin/uk/co/neviyn/booru/Controller.kt @@ -87,6 +87,9 @@ class ImageController } } } ?: return "gallery" + model.addAttribute("pageNumber", pageNumber) + val commonTags: List = tagRepository.find20TagsOnImages(images.content.map { it.id }) + model.addAttribute("commonTags", commonTags) model.addAttribute("imagePage", images) return "gallery" } diff --git a/src/main/kotlin/uk/co/neviyn/booru/Repository.kt b/src/main/kotlin/uk/co/neviyn/booru/Repository.kt index ab458c4..06ce673 100644 --- a/src/main/kotlin/uk/co/neviyn/booru/Repository.kt +++ b/src/main/kotlin/uk/co/neviyn/booru/Repository.kt @@ -32,4 +32,14 @@ interface ImageRepository : JpaRepository { interface TagRepository : CrudRepository { fun findByTagIs(tag: String): Tag? fun findAllByTagIn(tags: List): List + + //SELECT * FROM booru.tag t WHERE t.id IN (SELECT DISTINCT tag_id FROM booru.tag_image ti WHERE ti.image_id IN ?1) ORDER BY t.amount DESC, t.tag LIMIT 20 + //SELECT DISTINCT t.id, t.tag, t.amount FROM booru.tag t JOIN booru.tag_image ti ON ti.tag_id = t.id WHERE ti.image_id IN ?1 ORDER BY t.amount DESC, t.tag LIMIT 20 + //WITH x AS (SELECT DISTINCT tag_id FROM booru.tag_image ti WHERE ti.image_id in ?1) SELECT t.* FROM booru.tag t RIGHT JOIN x ON t.id = x.tag_id ORDER BY t.AMOUNT DESC, t.tag LIMIT 20 + @Suppress("SqlResolve") + @Query( + value = "SELECT * FROM booru.tag t WHERE t.id IN (SELECT DISTINCT tag_id FROM booru.tag_image ti WHERE ti.image_id IN ?1) ORDER BY t.amount DESC, t.tag LIMIT 20", + nativeQuery = true + ) + fun find20TagsOnImages(imageIDs: List): List } \ No newline at end of file diff --git a/src/main/resources/templates/fragments.html b/src/main/resources/templates/fragments.html index 7197617..b03d869 100644 --- a/src/main/resources/templates/fragments.html +++ b/src/main/resources/templates/fragments.html @@ -38,5 +38,21 @@ +
+
+
+ + +
+
+ +
+
+
\ No newline at end of file diff --git a/src/main/resources/templates/gallery.html b/src/main/resources/templates/gallery.html index 3e279a6..28ace7e 100644 --- a/src/main/resources/templates/gallery.html +++ b/src/main/resources/templates/gallery.html @@ -7,31 +7,70 @@
-
+
+
+
+ +
- - +
+
+
+ + + + + +
+
+
-
- -
- -
-
- -
-
-
-

No images found with all the specified tags.

+
+
+

No images found with all the specified tags.

+
+
+
+
+ +
diff --git a/src/main/resources/templates/landing.html b/src/main/resources/templates/landing.html index dd49e91..62de4f2 100644 --- a/src/main/resources/templates/landing.html +++ b/src/main/resources/templates/landing.html @@ -14,18 +14,20 @@
-
+ - + + +
diff --git a/src/main/resources/templates/single.html b/src/main/resources/templates/single.html index df7aff7..aa7c327 100644 --- a/src/main/resources/templates/single.html +++ b/src/main/resources/templates/single.html @@ -7,34 +7,27 @@
-
-
- - +
+
+
+ + + +
-
- +
+ +
- -
-
-
- -
- -
+
-
- -
-
\ No newline at end of file