diff --git a/src/main/kotlin/uk/co/neviyn/booru/Controller.kt b/src/main/kotlin/uk/co/neviyn/booru/Controller.kt index 5860171..8e7fbd1 100644 --- a/src/main/kotlin/uk/co/neviyn/booru/Controller.kt +++ b/src/main/kotlin/uk/co/neviyn/booru/Controller.kt @@ -39,7 +39,7 @@ class ImageController val page = PageRequest.of(pageNumber - 1, 20) if (tags != null) { val tagData = tags.mapNotNull { tagRepository.findByTagIs(it) } - val images = imageRepository.findByTagsIsContaining(tagData, page) + val images = imageRepository.findByTags(tagData, page) model.addAttribute("images", images) } else { // If no tag data supplied, just return all images val images = imageRepository.findAll(page) diff --git a/src/main/kotlin/uk/co/neviyn/booru/Repository.kt b/src/main/kotlin/uk/co/neviyn/booru/Repository.kt index 7d2939a..e9cedcb 100644 --- a/src/main/kotlin/uk/co/neviyn/booru/Repository.kt +++ b/src/main/kotlin/uk/co/neviyn/booru/Repository.kt @@ -3,6 +3,7 @@ package uk.co.neviyn.booru import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import org.springframework.data.repository.CrudRepository interface UserRepository : CrudRepository { @@ -12,7 +13,8 @@ interface UserRepository : CrudRepository { interface RoleRepository : CrudRepository interface ImageRepository : JpaRepository { - fun findByTagsIsContaining(tags: List, pageable: Pageable) : Page + @Query("select i from Image i where ?1 in (i.tags)") + fun findByTags(tags: List, pageable: Pageable) : Page } interface TagRepository : CrudRepository {