This is the complete implementation of a class which uses ContentStreamUpdateRequest to send data to the ExtractingRequestHandler.

   1 package javaapplicationsolrcell;
   2 
   3 import java.io.File;
   4 import java.io.IOException;
   5 import org.apache.solr.client.solrj.SolrServer;
   6 import org.apache.solr.client.solrj.SolrServerException;
   7 
   8 import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
   9 import org.apache.solr.client.solrj.response.QueryResponse;
  10 import org.apache.solr.client.solrj.SolrQuery;
  11 import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
  12 import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
  13 
  14 /**
  15  * @author EDaniel
  16  */
  17 public class SolrExampleTests {
  18 
  19   public static void main(String[] args) {
  20     try {
  21       //Solr cell can also index MS file (2003 version and 2007 version) types.
  22       String fileName = "c:/Sample.pdf"; 
  23       //this will be unique Id used by Solr to index the file contents.
  24       String solrId = "Sample.pdf"; 
  25       
  26       indexFilesSolrCell(fileName, solrId);
  27       
  28     } catch (Exception ex) {
  29       System.out.println(ex.toString());
  30     }
  31   }
  32   
  33   /**
  34    * Method to index all types of files into Solr. 
  35    * @param fileName
  36    * @param solrId
  37    * @throws IOException
  38    * @throws SolrServerException
  39    */
  40   public static void indexFilesSolrCell(String fileName, String solrId) 
  41     throws IOException, SolrServerException {
  42     
  43     String urlString = "http://localhost:8983/solr"; 
  44     SolrServer solr = new CommonsHttpSolrServer(urlString);
  45     
  46     ContentStreamUpdateRequest up 
  47       = new ContentStreamUpdateRequest("/update/extract");
  48     
  49     up.addFile(new File(fileName));
  50     
  51     up.setParam("literal.id", solrId);
  52     up.setParam("uprefix", "attr_");
  53     up.setParam("fmap.content", "attr_content");
  54     
  55     up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
  56     
  57     solr.request(up);
  58     
  59     QueryResponse rsp = solr.query(new SolrQuery("*:*"));
  60     
  61     System.out.println(rsp);
  62   }
  63 }

ContentStreamUpdateRequestExample (last edited 2010-05-28 19:06:12 by HossMan)