SOLR Environment Building and Java Demo

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.