From 9dbfe1ccc474624323a85d4c738d3edaa089d25e Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 11 Jan 2021 19:49:37 +0100 Subject: [PATCH] Check if paper object is not null before inserting --- src/main/java/org/RI/P2/Indexer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/RI/P2/Indexer.java b/src/main/java/org/RI/P2/Indexer.java index 3d2af20..0e66c72 100644 --- a/src/main/java/org/RI/P2/Indexer.java +++ b/src/main/java/org/RI/P2/Indexer.java @@ -80,11 +80,13 @@ public class Indexer { Document doc = new Document(); doc.add(new StringField("document_id", paper.paper_id, Field.Store.YES)); doc.add(new TextField("title", paper.metadata.title, Field.Store.YES)); + StringBuilder authors = new StringBuilder(); for (Author author : paper.metadata.authors) { String authorName = author.first + " " + author.middle + " " + author.last; authorName = authorName.replaceAll("\\p{P}", ""); - doc.add(new TextField("authors", authorName, Field.Store.YES)); + authors.append(authorName); } + doc.add(new TextField("authors", authors.toString(), Field.Store.YES)); StringBuilder fullAbstract = new StringBuilder(); for (Abstract abstract_ : paper.abstract_) { fullAbstract.append(abstract_.text); @@ -102,7 +104,9 @@ public class Indexer { createIndex(); for (File file : files) { Paper paper = parseJSONFile(file); - addDocument(paper); + if (paper != null) { + addDocument(paper); + } } commitChanges(); }