Forced ordering of search results

This commit is contained in:
neviyn 2021-04-30 16:56:19 +01:00
parent 0d325506e0
commit 90bb712bc3
2 changed files with 6 additions and 5 deletions

View File

@ -62,11 +62,11 @@ class ImageController
tagData.size != distinctTags.size -> null // Error if an invalid tag was supplied
tagData.size == 1 -> {
// Simpler query for single tag searches
val result = imageRepository.findAllByTagsContaining(tagData[0], page)
val result = imageRepository.findAllByTagsContainingOrderById(tagData[0], page)
if (result.isEmpty) null else result
}
else -> {
val result = imageRepository.findByTags(tagData, tagData.size.toLong(), page)
val result = imageRepository.findByTagsOrderById(tagData, tagData.size.toLong(), page)
if (result.isEmpty) null else result
}
}

View File

@ -14,13 +14,14 @@ interface RoleRepository : CrudRepository<Role, Long>
interface ImageRepository : JpaRepository<Image, Long> {
//@Query("select i from Image i join i.tags t where t in ?1 group by i.id having count(i.id) = ?2")
@Suppress("SqlResolve")
@Query(
value = "select * from booru.image i where i.id in (select image_id from booru.tag_image ti where ti.tag_id in ?1 group by ti.image_id having count(ti.image_id) = ?2)",
value = "select * from booru.image i where i.id in (select image_id from booru.tag_image ti where ti.tag_id in ?1 group by ti.image_id having count(ti.image_id) = ?2) order by i.id",
nativeQuery = true
)
fun findByTags(tagIDs: List<Tag>, tagCount: Long, pageable: Pageable): Page<Image>
fun findByTagsOrderById(tagIDs: List<Tag>, tagCount: Long, pageable: Pageable): Page<Image>
fun findAllByTagsContaining(tag: Tag, pageable: Pageable): Page<Image>
fun findAllByTagsContainingOrderById(tag: Tag, pageable: Pageable): Page<Image>
}
interface TagRepository : CrudRepository<Tag, Long> {