diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt index 5e34ad555..a63a83da2 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt @@ -99,7 +99,7 @@ class BookDtoDao( filterOnLibraryIds: Collection?, searchTerm: String?, ): Page { - 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) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt index 61237da20..9f6d14496 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt @@ -49,7 +49,7 @@ class ReadListDao( .firstOrNull() override fun findAll(search: String?, pageable: Pageable): Page { - 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, filterOnLibraryIds: Collection?, search: String?, pageable: Pageable): Page { - 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) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt index 7d13958ff..88b7724d3 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt @@ -48,7 +48,7 @@ class SeriesCollectionDao( .firstOrNull() override fun findAll(search: String?, pageable: Pageable): Page { - 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, filterOnLibraryIds: Collection?, search: String?, pageable: Pageable): Page { - 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) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt index 99f3a614d..72dd27edb 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt @@ -109,7 +109,7 @@ class SeriesDtoDao( override fun countByFirstCharacter(search: SeriesSearchWithReadProgress, userId: String): List { 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 { - 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)) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/search/LuceneHelper.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/search/LuceneHelper.kt index e2393d209..f3714b01f 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/search/LuceneHelper.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/search/LuceneHelper.kt @@ -30,7 +30,7 @@ class LuceneHelper( fun indexExists(): Boolean = DirectoryReader.indexExists(directory) - fun searchEntitiesIds(searchTerm: String?, entity: LuceneEntity, size: Int): List? { + fun searchEntitiesIds(searchTerm: String?, entity: LuceneEntity): List? { 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) { diff --git a/komga/src/test/kotlin/org/gotson/komga/infrastructure/search/SearchIndexLifecycleTest.kt b/komga/src/test/kotlin/org/gotson/komga/infrastructure/search/SearchIndexLifecycleTest.kt index e675d0b36..b59a9ceaa 100644 --- a/komga/src/test/kotlin/org/gotson/komga/infrastructure/search/SearchIndexLifecycleTest.kt +++ b/komga/src/test/kotlin/org/gotson/komga/infrastructure/search/SearchIndexLifecycleTest.kt @@ -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() }