From 6a3087cabd3062bdf983a4b4713c69a8db5e885f Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 11 Jan 2021 19:09:02 +0100 Subject: [PATCH] Move index file to .index --- src/main/java/org/RI/P2/Indexer.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/RI/P2/Indexer.java b/src/main/java/org/RI/P2/Indexer.java index 2c4d4fb..c0de104 100644 --- a/src/main/java/org/RI/P2/Indexer.java +++ b/src/main/java/org/RI/P2/Indexer.java @@ -19,6 +19,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.analysis.en.EnglishAnalyzer; import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; +import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; @@ -32,12 +33,14 @@ import com.google.gson.Gson; public class Indexer { IndexWriter index; - String folderPath; + String dataFolderPath; + String indexFolderPath; List files; PerFieldAnalyzerWrapper customAnalyzer; - Indexer(String folderPath) throws IOException, ParseException { - this.folderPath = folderPath; + Indexer(String dataFolderPath, String indexFolderPath) throws IOException, ParseException { + this.dataFolderPath = dataFolderPath; + this.indexFolderPath = indexFolderPath; files = readFiles(); customAnalyzer = createAnalyzer(); } @@ -46,13 +49,14 @@ public class Indexer { Map analyzerPerField = new HashMap<>(); analyzerPerField.put("title", new EnglishAnalyzer()); analyzerPerField.put("abstract", new EnglishAnalyzer()); + analyzerPerField.put("authors", new StandardAnalyzer()); PerFieldAnalyzerWrapper customAnalyzer = new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(), analyzerPerField); return customAnalyzer; } List readFiles() throws IOException { - List files = Files.walk(Paths.get(folderPath)).filter(Files::isRegularFile).map(Path::toFile) + List files = Files.walk(Paths.get(dataFolderPath)).filter(Files::isRegularFile).map(Path::toFile) .collect(Collectors.toList()); return files; } @@ -66,7 +70,7 @@ public class Indexer { } void createIndex() throws IOException { - Directory dir = FSDirectory.open(Paths.get(folderPath)); + Directory dir = FSDirectory.open(Paths.get(indexFolderPath)); IndexWriterConfig config = new IndexWriterConfig(customAnalyzer); config.setOpenMode(OpenMode.CREATE); index = new IndexWriter(dir, config); @@ -108,7 +112,7 @@ public class Indexer { usage(); } String dataDirectory = args[0]; - Indexer indexer = new Indexer(dataDirectory); + Indexer indexer = new Indexer(dataDirectory, ".index"); indexer.populateIndex(); } }