Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change 
notification.

The "SolrExampleTests" page has been changed by eDaniel.
http://wiki.apache.org/solr/SolrExampleTests?action=diff&rev1=3&rev2=4

--------------------------------------------------

  
  This page refers to http://wiki.apache.org/solr/ExtractingRequestHandler
  
- ||<tablewidth="80%">package javaapplicationsolrcell;<<BR>><<BR>>import 
java.io.File;<<BR>>import java.io.IOException;<<BR>>import 
org.apache.solr.client.solrj.SolrServer;<<BR>>import 
org.apache.solr.client.solrj.SolrServerException;<<BR>><<BR>>import 
org.apache.solr.client.solrj.request.AbstractUpdateRequest;<<BR>>import 
org.apache.solr.client.solrj.response.QueryResponse;<<BR>>import 
org.apache.solr.client.solrj.SolrQuery;<<BR>>import 
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;<<BR>>import 
org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;<<BR>><<BR>>/**<<BR>>
 *<<BR>> * @author EDaniel<<BR>> */<<BR>>public class 
SolrExampleTests{<<BR>><<BR>>  /**<<BR>>   * @param args the command line 
arguments<<BR>>   */<<BR>>  public static void main(String[] args) 
{<<BR>><<BR>>    SolrExampleTests myFiles = new SolrExampleTests();<<BR>><<BR>> 
   try {<<BR>><<BR>>      String fileName = "c:/Sample.pdf"; //Solr cell can 
also index MS file (2003 version and 2007 version) types.<<BR>>      String 
solrId = "Sample.pdf"; //this will be unique Id used by Solr to index the file 
contents.<<BR>><<BR>>      myFiles.IndexFilesSolrCell(fileName, 
solrId);<<BR>><<BR>>    } catch (Exception ex) {<<BR>>      
System.out.println(ex.toString());<<BR>>    }<<BR>><<BR>>  }<<BR>><<BR>>  
/**<<BR>>   * Method to index all types of files into Solr. Ref: 
http://wiki.apache.org/solr/ExtractingRequestHandler<<BR>>   * @param 
fileName<<BR>>   * @param solrId<<BR>>   * @throws IOException<<BR>>   * 
@throws SolrServerException<<BR>>   */<<BR>>  public void 
IndexFilesSolrCell(String fileName, String solrId) throws IOException, 
SolrServerException {<<BR>><<BR>>    ContentStreamUpdateRequest up = new 
ContentStreamUpdateRequest("/update/extract");<<BR>><<BR>>    up.addFile(new 
File(fileName));<<BR>><<BR>>    up.setParam("literal.id", solrId);<<BR>>    
up.setParam("uprefix", "attr_");<<BR>>    up.setParam("fmap.content", 
"attr_content");<<BR>><<BR>><<BR>>    
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);<<BR>><<BR>>    
String urlString = "http://localhost:8983/solr";;<<BR>>    SolrServer solr = new 
CommonsHttpSolrServer(urlString);<<BR>><<BR>>    solr.request(up);<<BR>><<BR>>  
  QueryResponse rsp = solr.query(new SolrQuery("*:*"));<<BR>><<BR>>    
System.out.println(rsp);<<BR>>  }<<BR>>}<<BR>> ||
+ ||<tablewidth="80%">package javaapplicationsolrcell;<<BR>><<BR>>import 
java.io.File;<<BR>>import java.io.IOException;<<BR>>import 
org.apache.solr.client.solrj.SolrServer;<<BR>>import 
org.apache.solr.client.solrj.SolrServerException;<<BR>><<BR>>import 
org.apache.solr.client.solrj.request.AbstractUpdateRequest;<<BR>>import 
org.apache.solr.client.solrj.response.QueryResponse;<<BR>>import 
org.apache.solr.client.solrj.SolrQuery;<<BR>>import 
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;<<BR>>import 
org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;<<BR>><<BR>>/**<<BR>>
 *<<BR>> * @author EDaniel<<BR>> */<<BR>>public class 
SolrExampleTests{<<BR>><<BR>>  /**<<BR>>   * @param args the command line 
arguments<<BR>>   */<<BR>>  public static void main(String[] args) 
{<<BR>><<BR>>    SolrExampleTests myFiles = new SolrExampleTests();<<BR>><<BR>> 
   try {<<BR>><<BR>>      String fileName = "c:/Sample.pdf"; //Solr cell can 
also index MS file (2003 version and 2007 version) types.<<BR>>      String 
solrId = "Sample.pdf"; //this will be unique Id used by Solr to index the file 
contents.<<BR>><<BR>>      myFiles.IndexFilesSolrCell(fileName, 
solrId);<<BR>><<BR>>    } catch (Exception ex) {<<BR>>      
System.out.println(ex.toString());<<BR>>    }<<BR>><<BR>>  }<<BR>><<BR>>  
/**<<BR>>   * Method to index all types of files into Solr.    * @param 
fileName<<BR>>   * @param solrId<<BR>>   * @throws IOException<<BR>>   * 
@throws SolrServerException<<BR>>   */<<BR>>  public void 
IndexFilesSolrCell(String fileName, String solrId) throws IOException, 
SolrServerException {<<BR>><<BR>>    ContentStreamUpdateRequest up = new 
ContentStreamUpdateRequest("/update/extract");<<BR>><<BR>>    up.addFile(new 
File(fileName));<<BR>><<BR>>    up.setParam("literal.id", solrId);<<BR>>    
up.setParam("uprefix", "attr_");<<BR>>    up.setParam("fmap.content", 
"attr_content");<<BR>><<BR>><<BR>>    
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);<<BR>><<BR>>    
String urlString = "http://localhost:8983/solr";;    SolrServer solr = new 
CommonsHttpSolrServer(urlString);<<BR>><<BR>>    solr.request(up);<<BR>><<BR>>  
  QueryResponse rsp = solr.query(new SolrQuery("*:*"));<<BR>><<BR>>    
System.out.println(rsp);<<BR>>  }<<BR>>}<<BR>> ||
  

Reply via email to