1 | package org.hathitrust.extractedfeatures;
|
---|
2 |
|
---|
3 | import org.apache.spark.api.java.function.Function;
|
---|
4 | import org.apache.spark.api.java.function.MapFunction;
|
---|
5 | import org.apache.spark.util.DoubleAccumulator;
|
---|
6 | import org.json.JSONObject;
|
---|
7 |
|
---|
8 |
|
---|
9 | class PerPageJSONMap implements Function<JSONObject, String>
|
---|
10 | {
|
---|
11 | private static final long serialVersionUID = 1L;
|
---|
12 |
|
---|
13 | protected String _input_dir;
|
---|
14 | protected String _solr_url;
|
---|
15 | protected String _output_dir;
|
---|
16 | protected int _verbosity;
|
---|
17 |
|
---|
18 | protected DoubleAccumulator _progress_accum;
|
---|
19 | protected double _progress_step;
|
---|
20 |
|
---|
21 |
|
---|
22 | public PerPageJSONMap(String input_dir, String solr_url, String output_dir, int verbosity,
|
---|
23 | DoubleAccumulator progress_accum, double progress_step)
|
---|
24 | {
|
---|
25 | _input_dir = input_dir;
|
---|
26 | _solr_url = solr_url;
|
---|
27 | _output_dir = output_dir;
|
---|
28 | _verbosity = verbosity;
|
---|
29 |
|
---|
30 | _progress_accum = progress_accum;
|
---|
31 | _progress_step = progress_step;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public String call(JSONObject solr_add_doc_json)
|
---|
35 | {
|
---|
36 | String output_json_bz2 = solr_add_doc_json.getString("filename_json_bz2");
|
---|
37 | solr_add_doc_json.remove("filename_json_bz2");
|
---|
38 |
|
---|
39 | boolean random_test = (Math.random()>0.999); // every 1000
|
---|
40 |
|
---|
41 | if ((_verbosity >=2) && (random_test)) {
|
---|
42 | System.out.println("==================");
|
---|
43 | System.out.println("Sample output Solr add JSON [random test 1/1000]: " + solr_add_doc_json.toString());
|
---|
44 | System.out.println("==================");
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | if (_solr_url != null) {
|
---|
49 | if ((_verbosity >=2) && (random_test)) {
|
---|
50 | System.out.println("==================");
|
---|
51 | System.out.println("Posting to: " + _solr_url);
|
---|
52 | System.out.println("==================");
|
---|
53 | }
|
---|
54 | SolrDocJSON.postSolrDoc(_solr_url, solr_add_doc_json);
|
---|
55 | }
|
---|
56 |
|
---|
57 | if (_output_dir != null) {
|
---|
58 | if ((_verbosity >=2) && (random_test)) {
|
---|
59 | System.out.println("==================");
|
---|
60 | System.out.println("Saving to: " + _output_dir);
|
---|
61 | System.out.println("==================");
|
---|
62 | }
|
---|
63 | SolrDocJSON.saveSolrDoc(solr_add_doc_json, _output_dir + "/" + output_json_bz2);
|
---|
64 | }
|
---|
65 |
|
---|
66 | return output_json_bz2;
|
---|
67 | }
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|