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