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

[#4180] Lucene crashes with some specific messages #4181

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,88 @@
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexableField;
import co.airy.log.AiryLoggerFactory;
import org.slf4j.Logger;

import java.util.List;

import static java.util.stream.Collectors.toList;

public class DocumentMapper {

private static final Logger log = AiryLoggerFactory.getLogger(DocumentMapper.class);

public Document fromConversationIndex(ConversationIndex conversation) {
final Document document = new Document();
document.add(new StringField("id", conversation.getId(), Field.Store.YES));
document.add(new StringField("channel_id", conversation.getChannelId(), Field.Store.YES));
final Document document = new Document();

if (conversation.getDisplayName() != null) {
if (conversation.getId() != null) {
document.add(new StringField("id", conversation.getId(), Field.Store.YES));
} else {
log.error("conversation.getId() is null");
}

if (conversation.getChannelId() != null) {
document.add(new StringField("channel_id", conversation.getChannelId(), Field.Store.YES));
} else {
log.error("conversation.getChannelId() is null");
}

if (conversation.getDisplayName() != null) {
document.add(new TextField("display_name", conversation.getDisplayName(), Field.Store.YES));
} else {
log.error("conversation.getDisplayName() is null");
}
document.add(new StringField("source", conversation.getSource(), Field.Store.YES));

document.add(new LongPoint("created_at", conversation.getCreatedAt()));
document.add(new StoredField("created_at", conversation.getCreatedAt()));
document.add(new IntPoint("unread_count", conversation.getUnreadMessageCount()));
document.add(new StoredField("unread_count", conversation.getUnreadMessageCount()));

// sort enabled field
document.add(new NumericDocValuesField("last_message_at", conversation.getLastMessageAt()));
for (String tagId : conversation.getTagIds()) {
document.add(new TextField("tag_ids", tagId, Field.Store.YES));

if (conversation.getSource() != null) {
document.add(new StringField("source", conversation.getSource(), Field.Store.YES));
} else {
log.error("conversation.getSource() is null");
}

for (MetadataNode node : conversation.getMetadata()) {
final String key = String.format("metadata.%s", node.getKey());
// Index but don't store metadata
document.add(new TextField(key, node.getValue(), Field.Store.NO));

if (conversation.getCreatedAt() != null) {
document.add(new LongPoint("created_at", conversation.getCreatedAt()));
document.add(new StoredField("created_at", conversation.getCreatedAt()));
} else {
log.error("conversation.getCreatedAt() is null");
}


if (conversation.getUnreadMessageCount() != null) {
document.add(new IntPoint("unread_count", conversation.getUnreadMessageCount()));
document.add(new StoredField("unread_count", conversation.getUnreadMessageCount()));
} else {
log.error("conversation.getUnreadMessageCount() is null");
}

if (conversation.getLastMessageAt() != null) {
document.add(new NumericDocValuesField("last_message_at", conversation.getLastMessageAt()));
} else {
log.error("conversation.getLastMessageAt() is null");
}

if (conversation.getTagIds() != null) {
for (String tagId : conversation.getTagIds()) {
document.add(new TextField("tag_ids", tagId, Field.Store.YES));
}
} else {
log.error("conversation.getTagIds() is null");
}

if (conversation.getMetadata() != null) {
for (MetadataNode node : conversation.getMetadata()) {
final String key = String.format("metadata.%s", node.getKey());
if (node.getValue() != null) {
document.add(new TextField(key, node.getValue(), Field.Store.NO));
} else {
log.error("Metadata value for key \" + node.getKey() + \" is null");
}
}
} else {
log.error("conversation.getMetadata() is null");
}

return document;
}


public ConversationIndex fromDocument(Document document) {
final Long createdAt = document.getField("created_at").numericValue().longValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public LuceneProvider() throws IOException {

@Override
public void put(ConversationIndex conversation) throws IOException {
final Document document = this.documentMapper.fromConversationIndex(conversation);
writer.updateDocument(new Term("id", conversation.getId()), document);
if (conversation != null) {
final Document document = this.documentMapper.fromConversationIndex(conversation);
writer.updateDocument(new Term("id", conversation.getId()), document);
}
}

@Override
Expand Down
Loading