Skip to content

Instantly share code, notes, and snippets.

@mdellabitta
Created July 2, 2013 15:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdellabitta/5910253 to your computer and use it in GitHub Desktop.
Save mdellabitta/5910253 to your computer and use it in GitHub Desktop.
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