Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Expand Down Expand Up @@ -63,29 +62,31 @@ public void addMapping() {
/**
* Method of importing training set in to Elasticsearch
*
* @param dataFolder the path to the traing set
* @throws IOException IOException
* @param dataFolder
* the path to the traing set
* @throws IOException
* IOException
*/
public void importTrainingSet(String dataFolder) throws IOException {
es.createBulkProcessor();

File[] files = new File(dataFolder).listFiles();
for (File file : files) {
BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()));
br.readLine();
String line = br.readLine();
while (line != null) {
String[] list = line.split(",");
String query = file.getName().replace(".csv", "");
if (list.length > 0) {
IndexRequest ir = new IndexRequest(props.getProperty(MudrodConstants.ES_INDEX_NAME), "trainingranking")
.source(jsonBuilder().startObject().field("query", query).field("dataID", list[0]).field("label", list[list.length - 1]).endObject());
es.getBulkProcessor().add(ir);
try (BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()))) {
String line = null;
line = br.readLine(); // cvs header
while ((line = br.readLine()) != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this code? It look suspicious.

String[] list = line.split(",");
String query = file.getName().replace(".csv", "");
if (list.length > 0) {
IndexRequest ir = new IndexRequest(props.getProperty(MudrodConstants.ES_INDEX_NAME), "trainingranking")
.source(jsonBuilder().startObject().field("query", query).field("dataID", list[0]).field("label", list[list.length - 1]).endObject());
es.getBulkProcessor().add(ir);
}
}
line = br.readLine();
}
br.close();
}

es.destroyBulkProcessor();
}
}