One configuration SOLR environment
1. Download SOLR
2. Configure SOLR (preferably separate one tomcat, one machine to boot multiple tomcat see: http://www.cnblogs.com/lxlwellaccessful/p/6746341.html)
A. In the download of the Solr folder under the \example\solr\ file all the files into a folder (I was placed in the E:\MySoft\solr\home)
B. Initializing an SOLR instance
There is a solr.war under the \example\webapps\ path of the SOLR decompression path, copy it to Tomcat WebApp under compile
C. Modify the configuration file, page Access SOLR management interface
Next start Tomcat, and if you follow the steps then you can see this page by visiting SOLR under the Tomcat, then the SOLR configuration is complete
Two, Java Operation SOLR
1.jar Pack (many online)
Here is the code for my demo
1 Packagecom.hlrj.lxl.test;2 3 Importjava.io.IOException;4 Importjava.util.ArrayList;5 Importjava.util.List;6 7 ImportOrg.apache.solr.client.solrj.SolrQuery;8 Importorg.apache.solr.client.solrj.SolrServerException;9 ImportOrg.apache.solr.client.solrj.impl.HttpSolrServer;Ten ImportOrg.apache.solr.client.solrj.response.QueryResponse; One ImportOrg.apache.solr.client.solrj.response.UpdateResponse; A Importorg.apache.solr.common.SolrDocumentList; - ImportOrg.apache.solr.update.SolrCmdDistributor.Response; - the ImportCom.hlrj.lxl.bean.SolrTestBean; - ImportCom.hlrj.lxl.bean.SorlBean; - Importcom.hlrj.lxl.util.SorlUtils; - + Public classSolrtest { - + Public Static voidMain (string[] args) { A //Get SOLR Services atHttpsolrserver hs=NewHttpsolrserver ("HTTP://LOCALHOST:8888/SOLR"); - /*sorlutils sorlutils=sorlutils.getinstance ();*/ - //SOLR Object Entity -Solrtestbean sb=NewSolrtestbean (); -Sb.setid ("1"); -Sb.settitle ("Hello Word!!!"); inList<solrtestbean> lst=NewArraylist<solrtestbean>(); - for(inti=2;i<15;i++) { tosb=NewSolrtestbean (); +Sb.setid (i+ ""); -Sb.settitle ("Hello Word!!!" +i); the Lst.add (SB); * } $ Try {Panax Notoginseng - //Add Data the //updateresponse Ur=hs.addbean (SB); + //hs.commit ();//Submit A //Add bulk Data the //updateresponse Ur=hs.addbeans (LST); + //hs.commit ();//Submit - //Delete Data $ //Hs.deletebyid ("1"); $ //hs.commit ();//Submit - - //Querying Data theSolrquery query=NewSolrquery ("Hello word"); -Query.setrows (15);Wuyi //Get Query Response object theQueryresponse response=hs.query (query); - //get returned result set WuSolrdocumentlist doclist=response.getresults (); - About for(intI=0;i<doclist.getnumfound () -1;i++) $ { -SYSTEM.OUT.PRINTLN ("ID:" +doclist.get (i). Get ("id") + "---title:" +doclist.get (i). Get ("title")); - } - A /*int result= ur.getstatus (); + System.out.println (result);*/ the}Catch(Exception e) { - //TODO auto-generated Catch block $ e.printstacktrace (); the } the } the}
SOLR Environment Building and Java Demo