Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Lucene search engine updates from being interrupted #4681

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,6 @@
package run.halo.app.search.post;

import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.lucene.document.Field.Store.YES;
import static org.apache.lucene.index.IndexWriterConfig.OpenMode.CREATE_OR_APPEND;

Expand Down Expand Up @@ -40,7 +41,6 @@
import org.springframework.beans.factory.DisposableBean;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import reactor.core.Exceptions;
import run.halo.app.infra.properties.HaloProperties;
import run.halo.app.search.SearchParam;
import run.halo.app.search.SearchResult;
Expand Down Expand Up @@ -121,16 +121,17 @@ public void addDocuments(List<PostDoc> posts) throws IOException {
writeConfig.setOpenMode(CREATE_OR_APPEND);
try (var writer = new IndexWriter(postIndexDir, writeConfig)) {
posts.forEach(post -> {
var doc = this.convert(post);
try {
var doc = this.convert(post);
var seqNum =
writer.updateDocument(new Term(PostDoc.ID_FIELD, post.name()), doc);
if (log.isDebugEnabled()) {
log.debug("Updated document({}) with sequence number {} returned",
post.name(), seqNum);
}
} catch (IOException e) {
throw Exceptions.propagate(e);
} catch (Throwable e) {
// Continue next update
log.error("Failed to update document for post {}", post.name(), e);
}
});
}
Expand Down Expand Up @@ -180,8 +181,8 @@ private Document convert(PostDoc post) {
var doc = new Document();
doc.add(new StringField("name", post.name(), YES));
doc.add(new TextField("title", post.title(), YES));
doc.add(new TextField("excerpt", post.excerpt(), YES));
doc.add(new TextField("content", post.content(), YES));
doc.add(new TextField("excerpt", defaultString(post.excerpt()), YES));
doc.add(new TextField("content", defaultString(post.content()), YES));

var publishTimestamp = post.publishTimestamp().getEpochSecond();
doc.add(new LongPoint("publishTimestamp", publishTimestamp));
Expand Down