Created
July 2, 2013 15:25
-
-
Save mdellabitta/5910253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.io.*; | |
import org.apache.hadoop.mapreduce.Mapper; | |
public class SolrMapper extends Mapper<LongWritable, Text, Text, Text> { | |
private HttpSolrServer solrServer; | |
private Text outKey = new Text(); | |
@Override | |
protected void setup(Context context) throws IOException, InterruptedException { | |
super.setup(context); | |
Configuration config = context.getConfiguration(); | |
solrServer = new HttpSolrServer(config.get("solr.url")); | |
} | |
@Override | |
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { | |
try { | |
File fileToProcess = new File(value.toString()); | |
//build SolrInputDocument from file | |
SolrInputDocument solrInputDocument = null; //todo | |
String docKey = null; //hang on to the document id for reporting | |
solrServer.add(solrInputDocument); | |
outKey.set(docKey); | |
context.write(docKey, docKey); | |
} catch (Exception e) { | |
System.err.println("Caught exception processing " + value.toString()); | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment