From 5139f0a38d9d3fb5cadca9e26356e6d9395f2e5c Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 11 Jan 2021 20:20:54 +0100 Subject: [PATCH] Refactor addDocument function --- src/main/java/org/RI/P2/Indexer.java | 34 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/RI/P2/Indexer.java b/src/main/java/org/RI/P2/Indexer.java index b00d5be..6da3198 100644 --- a/src/main/java/org/RI/P2/Indexer.java +++ b/src/main/java/org/RI/P2/Indexer.java @@ -79,28 +79,40 @@ public class Indexer { index = new IndexWriter(dir, config); } - void addDocument(Paper paper) throws IOException { - 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(); - StringBuilder institutions = new StringBuilder(); - StringBuilder emails = new StringBuilder(); + void populatePaperMetadata(Paper paper, StringBuilder authors, StringBuilder institutions, StringBuilder emails) { for (Author author : paper.metadata.authors) { - String authorName = author.first + " " + author.middle + " " + author.last; + String authorName = author.first + " " + author.middle + " " + author.last + " "; authorName = authorName.replaceAll("\\p{P}", ""); authors.append(authorName); institutions.append(author.affiliation.institution); emails.append(author.email); } + } + + void populateFullAbstract(Paper paper, StringBuilder fullAbstract) { + for (Abstract abstr : paper.abstr) { + fullAbstract.append(abstr.text); + } + } + + void populateDocumentFields(Paper paper, Document doc) { + 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(); + StringBuilder institutions = new StringBuilder(); + StringBuilder emails = new StringBuilder(); + populatePaperMetadata(paper, authors, institutions, emails); doc.add(new TextField("authors", authors.toString(), Field.Store.YES)); doc.add(new TextField("institution", institutions.toString(), Field.Store.NO)); doc.add(new TextField("emails", emails.toString(), Field.Store.NO)); StringBuilder fullAbstract = new StringBuilder(); - for (Abstract abstr : paper.abstr) { - fullAbstract.append(abstr.text); - } + populateFullAbstract(paper, fullAbstract); doc.add(new TextField("abstract", fullAbstract.toString(), Field.Store.NO)); + } + + void addDocument(Paper paper) throws IOException { + Document doc = new Document(); + populateDocumentFields(paper, doc); index.addDocument(doc); }