fix(api): incorrect page information when searching

This commit is contained in:
Gauthier Roebroeck 2021-09-10 15:15:27 +08:00
parent 57f601b8dd
commit 24b564a707
6 changed files with 33 additions and 33 deletions

View file

@ -99,7 +99,7 @@ class BookDtoDao(
filterOnLibraryIds: Collection<String>?,
searchTerm: String?,
): Page<BookDto> {
val bookIds = luceneHelper.searchEntitiesIds(searchTerm, LuceneEntity.Book, if (pageable.isPaged) pageable.pageSize else 20)
val bookIds = luceneHelper.searchEntitiesIds(searchTerm, LuceneEntity.Book)
val searchCondition = b.ID.inOrNoCondition(bookIds)
val count = dsl.selectDistinct(b.ID)

View file

@ -49,7 +49,7 @@ class ReadListDao(
.firstOrNull()
override fun findAll(search: String?, pageable: Pageable): Page<ReadList> {
val readListIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.ReadList, if (pageable.isPaged) pageable.pageSize else 20)
val readListIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.ReadList)
val searchCondition = rl.ID.inOrNoCondition(readListIds)
val count = dsl.selectCount()
@ -79,7 +79,7 @@ class ReadListDao(
}
override fun findAllByLibraryIds(belongsToLibraryIds: Collection<String>, filterOnLibraryIds: Collection<String>?, search: String?, pageable: Pageable): Page<ReadList> {
val readListIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.ReadList, if (pageable.isPaged) pageable.pageSize else 20)
val readListIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.ReadList)
val searchCondition = rl.ID.inOrNoCondition(readListIds)
val conditions = b.LIBRARY_ID.`in`(belongsToLibraryIds)

View file

@ -48,7 +48,7 @@ class SeriesCollectionDao(
.firstOrNull()
override fun findAll(search: String?, pageable: Pageable): Page<SeriesCollection> {
val collectionIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.Collection, if (pageable.isPaged) pageable.pageSize else 20)
val collectionIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.Collection)
val searchCondition = c.ID.inOrNoCondition(collectionIds)
val count = dsl.selectCount()
@ -78,7 +78,7 @@ class SeriesCollectionDao(
}
override fun findAllByLibraryIds(belongsToLibraryIds: Collection<String>, filterOnLibraryIds: Collection<String>?, search: String?, pageable: Pageable): Page<SeriesCollection> {
val collectionIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.Collection, if (pageable.isPaged) pageable.pageSize else 20)
val collectionIds = luceneHelper.searchEntitiesIds(search, LuceneEntity.Collection)
val searchCondition = c.ID.inOrNoCondition(collectionIds)
val conditions = s.LIBRARY_ID.`in`(belongsToLibraryIds)

View file

@ -109,7 +109,7 @@ class SeriesDtoDao(
override fun countByFirstCharacter(search: SeriesSearchWithReadProgress, userId: String): List<GroupCountDto> {
val conditions = search.toCondition()
val joinConditions = search.toJoinConditions()
val seriesIds = luceneHelper.searchEntitiesIds(search.searchTerm, LuceneEntity.Series, 20)
val seriesIds = luceneHelper.searchEntitiesIds(search.searchTerm, LuceneEntity.Series)
val searchCondition = s.ID.inOrNoCondition(seriesIds)
val firstChar = lower(substring(d.TITLE_SORT, 1, 1))
@ -167,7 +167,7 @@ class SeriesDtoDao(
joinConditions: JoinConditions = JoinConditions(),
searchTerm: String?,
): Page<SeriesDto> {
val seriesIds = luceneHelper.searchEntitiesIds(searchTerm, LuceneEntity.Series, if (pageable.isPaged) pageable.pageSize else 20)
val seriesIds = luceneHelper.searchEntitiesIds(searchTerm, LuceneEntity.Series)
val searchCondition = s.ID.inOrNoCondition(seriesIds)
val count = dsl.select(count(s.ID))

View file

@ -30,7 +30,7 @@ class LuceneHelper(
fun indexExists(): Boolean = DirectoryReader.indexExists(directory)
fun searchEntitiesIds(searchTerm: String?, entity: LuceneEntity, size: Int): List<String>? {
fun searchEntitiesIds(searchTerm: String?, entity: LuceneEntity): List<String>? {
return if (!searchTerm.isNullOrBlank()) {
try {
val fieldsQuery = MultiFieldQueryParser(entity.defaultFields, analyzer).apply {
@ -46,7 +46,7 @@ class LuceneHelper(
getIndexReader().use { index ->
val searcher = IndexSearcher(index)
val topDocs = searcher.search(booleanQuery, size)
val topDocs = searcher.search(booleanQuery, index.numDocs())
topDocs.scoreDocs.map { searcher.doc(it.doc)[entity.id] }
}
} catch (e: ParseException) {

View file

@ -101,7 +101,7 @@ class SearchIndexLifecycleTest(
val series = seriesLifecycle.createSeries(makeSeries("Series", libraryId = library.id))
seriesLifecycle.addBooks(series, listOf(makeBook("book", seriesId = series.id, libraryId = library.id)))
val found = luceneHelper.searchEntitiesIds("book", LuceneEntity.Book, 10)
val found = luceneHelper.searchEntitiesIds("book", LuceneEntity.Book)
assertThat(found).isNotNull
assertThat(found).hasSize(1)
@ -113,7 +113,7 @@ class SearchIndexLifecycleTest(
val book = makeBook("book", seriesId = series.id, libraryId = library.id)
seriesLifecycle.addBooks(series, listOf(book))
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book, 10).let { found ->
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -123,11 +123,11 @@ class SearchIndexLifecycleTest(
}
mockEventPublisher.publishEvent(DomainEvent.BookUpdated(book))
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book, 10).let { found ->
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
luceneHelper.searchEntitiesIds("updated", LuceneEntity.Book, 10).let { found ->
luceneHelper.searchEntitiesIds("updated", LuceneEntity.Book).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -139,14 +139,14 @@ class SearchIndexLifecycleTest(
val book = makeBook("book", seriesId = series.id, libraryId = library.id)
seriesLifecycle.addBooks(series, listOf(book))
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book, 10).let { found ->
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
bookLifecycle.deleteOne(book)
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book, 10).let { found ->
luceneHelper.searchEntitiesIds("book", LuceneEntity.Book).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
@ -159,7 +159,7 @@ class SearchIndexLifecycleTest(
fun `given empty index when adding an entity then it is added to the index`() {
seriesLifecycle.createSeries(makeSeries("Series", libraryId = library.id))
val found = luceneHelper.searchEntitiesIds("series", LuceneEntity.Series, 10)
val found = luceneHelper.searchEntitiesIds("series", LuceneEntity.Series)
assertThat(found).isNotNull
assertThat(found).hasSize(1)
@ -169,7 +169,7 @@ class SearchIndexLifecycleTest(
fun `given an entity when updating then it is updated in the index`() {
val series = seriesLifecycle.createSeries(makeSeries("Series", libraryId = library.id))
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series, 10).let { found ->
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -179,11 +179,11 @@ class SearchIndexLifecycleTest(
}
mockEventPublisher.publishEvent(DomainEvent.SeriesUpdated(series))
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series, 10).let { found ->
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
luceneHelper.searchEntitiesIds("updated", LuceneEntity.Series, 10).let { found ->
luceneHelper.searchEntitiesIds("updated", LuceneEntity.Series).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -193,14 +193,14 @@ class SearchIndexLifecycleTest(
fun `given an entity when deleting then it is removed from the index`() {
val series = seriesLifecycle.createSeries(makeSeries("Series", libraryId = library.id))
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series, 10).let { found ->
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
seriesLifecycle.deleteMany(listOf(series))
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series, 10).let { found ->
luceneHelper.searchEntitiesIds("series", LuceneEntity.Series).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
@ -214,7 +214,7 @@ class SearchIndexLifecycleTest(
val collection = SeriesCollection("collection")
collectionLifecycle.addCollection(collection)
val found = luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection, 10)
val found = luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection)
assertThat(found).isNotNull
assertThat(found).hasSize(1)
@ -225,7 +225,7 @@ class SearchIndexLifecycleTest(
val collection = SeriesCollection("collection")
collectionLifecycle.addCollection(collection)
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection, 10).let { found ->
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -235,11 +235,11 @@ class SearchIndexLifecycleTest(
}
mockEventPublisher.publishEvent(DomainEvent.CollectionUpdated(collection))
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection, 10).let { found ->
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
luceneHelper.searchEntitiesIds("updated", LuceneEntity.Collection, 10).let { found ->
luceneHelper.searchEntitiesIds("updated", LuceneEntity.Collection).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -250,14 +250,14 @@ class SearchIndexLifecycleTest(
val collection = SeriesCollection("collection")
collectionLifecycle.addCollection(collection)
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection, 10).let { found ->
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
collectionLifecycle.deleteCollection(collection)
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection, 10).let { found ->
luceneHelper.searchEntitiesIds("collection", LuceneEntity.Collection).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
@ -271,7 +271,7 @@ class SearchIndexLifecycleTest(
val readList = ReadList("readlist")
readListLifecycle.addReadList(readList)
val found = luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList, 10)
val found = luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList)
assertThat(found).isNotNull
assertThat(found).hasSize(1)
@ -282,7 +282,7 @@ class SearchIndexLifecycleTest(
val readList = org.gotson.komga.domain.model.ReadList("readlist")
readListLifecycle.addReadList(readList)
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList, 10).let { found ->
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -292,11 +292,11 @@ class SearchIndexLifecycleTest(
}
mockEventPublisher.publishEvent(DomainEvent.ReadListUpdated(readList))
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList, 10).let { found ->
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}
luceneHelper.searchEntitiesIds("updated", LuceneEntity.ReadList, 10).let { found ->
luceneHelper.searchEntitiesIds("updated", LuceneEntity.ReadList).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
@ -307,14 +307,14 @@ class SearchIndexLifecycleTest(
val readList = org.gotson.komga.domain.model.ReadList("readlist")
readListLifecycle.addReadList(readList)
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList, 10).let { found ->
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList).let { found ->
assertThat(found).isNotNull
assertThat(found).hasSize(1)
}
readListLifecycle.deleteReadList(readList)
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList, 10).let { found ->
luceneHelper.searchEntitiesIds("readlist", LuceneEntity.ReadList).let { found ->
assertThat(found).isNotNull
assertThat(found).isEmpty()
}