Skip to content

Commit

Permalink
fix lucene index not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Dec 29, 2024
1 parent 9f9c8ca commit 807bbd2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,32 @@ class LuceneTopicSearchService(private val path: Path) : TopicSearchService {
parent: Pair<PrimaryKey?, ObjectType>?
): Result<PaginationResult<TopicDocument>> {
return useLucene {
DirectoryReader.open(it).use { reader ->
val searcher = IndexSearcher(reader)
val combinedQuery = buildQuery(nextTopicId, word, root, parent)
Napier.i {
"lucene search query $combinedQuery"
}
val sortById = Sort(SortField("id2", SortField.Type.LONG, true))
val docs = searcher.search(combinedQuery.build(), size, sortById)
val scoreDocs = docs.scoreDocs
PaginationResult(scoreDocs.mapNotNull { doc ->
searcher.storedFields().document(doc.doc)?.let { document ->
val content = document.get("content")
val id = document.get("id1").toPrimaryKeyOrNull()
if (content != null && id != null) {
restoreDocument(id, document)
} else {
null
}
try {
DirectoryReader.open(it).use { reader ->
val searcher = IndexSearcher(reader)
val combinedQuery = buildQuery(nextTopicId, word, root, parent)
Napier.i {
"lucene search query $combinedQuery"
}
}, docs.totalHits.value)
val sortById = Sort(SortField("id2", SortField.Type.LONG, true))
val docs = searcher.search(combinedQuery.build(), size, sortById)
val scoreDocs = docs.scoreDocs
PaginationResult(scoreDocs.mapNotNull { doc ->
searcher.storedFields().document(doc.doc)?.let { document ->
val content = document.get("content")
val id = document.get("id1").toPrimaryKeyOrNull()
if (content != null && id != null) {
restoreDocument(id, document)
} else {
null
}
}
}, docs.totalHits.value)
}
} catch (e: IndexNotFoundException) {
PaginationResult(emptyList(), 0)
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ services:
- INTERCEPTED_ERROR_CODES=
- REVERSE_PROXY_WS=yes
- REVERSE_PROXY_INTERCEPT_ERRORS=no
- USE_BAD_BEHAVIOR=no
- USE_BAD_BEHAVIOR=yes
- BAD_BEHAVIOR_STATUS_CODES=400 403 404 405 429 444
- USE_MODSECURITY_CRS=no
networks:
Expand Down

0 comments on commit 807bbd2

Please sign in to comment.