Check if paper object is not null before inserting

This commit is contained in:
coolneng 2021-01-11 19:49:37 +01:00
parent a4d505ce06
commit 9dbfe1ccc4
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 6 additions and 2 deletions

View File

@ -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();
}