Apache SOLR (i)

Source: Internet
Author: User
Tags apache solr solr

Concept:Apache SOLR is an open-source search server. SOLR is developed using the Java language, mainly based on HTTP and Apache Lucene implementations. The resources stored in Apache SOLR are stored as objects in Document. Each document consists of a series of field, and each field represents a property of the resource. Each Document in SOLR needs to have a property that uniquely identifies itself, by default the name of the property is the ID and is described in the Schema configuration file using:<uniquekey>id</uniquekey>. SOLR is a high performance, JAVA5 developed, Lucene -based full-text search server. SOLR is a standalone enterprise search Application Server, and many enterprises currently use SOLR open Source Services. The principle is roughly that the document is added to a search collection via HTTP using XML. Querying the collection is also achieved by receiving a xml/JSON response over HTTP. Its main features include: efficient, flexible caching, vertical search, highlighting search results, improving usability through index replication, providing a powerful data schema for defining fields, types and setting up text Analysis , providing web-based management interfaces, and more. all versions of SOLR:http://archive.apache.org/dist/lucene/solr/ installation configuration and program insertion and query 1. Start SOLR command-line window into the installation directory under the bin, directly using SOLR start, no parameters default to use 8983 port

2. Visit SOLR consoleAddress:http://localhost:8983/solr Enter SOLR's console. SOLR is the core of its work and can be understood as a database table. Each core has its own schema, which corresponds to a field that is understood as a database. the console as shown. Currently there is no core file, we need to configure it ourselves.

3. Configure the Coreconfigure our own core. In the left menu of the console, select Core Admin and go to the core new page. before clicking on Add Core Save, go to the SERVER-SOLR installation directory and create a new folder with the same name as the Core, such as:Enter E:\DEVELOPENVIRONMENT\SOLR\SOLR-6.2.0\SERVER\SOLR to create a new democore. After the folder is set up , go to the SOLR directory under Server\solr\configsets\basic_configs and copy the Conf folder to the new foldersuch as: Enter the E:\DevelopEnvironment\solr\solr-6.2.0\server\solr\configsets\basic_configs copy conf folder to the newly created Democore

After completing this step, go back to the console core Admin input name and dir click on Add Core to save

after the save is complete, you can see the core:

the corresponding folder contents are also changed to:

4. New Schemawhen the core file is created, it creates its corresponding schema. go to the core's schema menu, click Add Field, and in the popup page, enter name and Type,name to represent the names of the fields, type, type, select Text_general. stored means that the value of the field is stored and used for subsequent indexing. indexed indicates that the field is indexed. After the entry is complete, click Add Field to save. at this point, both core and schema are built. The next step is to insert the data into the SOLR core. 5, using the program to insert dataCreate a new Java project and copy the corresponding jar package from SOLR to your project. The jar package used in the Dist folder, mainly including SOLRJ the jar package and solr-lib under the jar package, for convenience, all directly copy the past can be. such as: E:\solr-6.5.1\dist E:\solr-6.5.1\dist\solrj-liband running the program to insert the program
        Httpsolrclient.builder Builder = new Httpsolrclient.builder ("Http://localhost:8983/solr/democore");                 Httpsolrclient solrclient = Builder.build ();                 Solrinputdocument document = new Solrinputdocument ();                Document.addfield ("id", System.currenttimemillis () + "");                Document.addfield ("title", "Computer Science and Technology" + system.currenttimemillis ());                 Solrclient.add (document);                 Solrclient.commit ();                Solrclient.close ();

  

6. Use the program to query dataHttpsolrclient.builder Builder = new httpsolrclient.builder ("Http://localhost:8983/solr/democore" );httpsolrclient solrclient = Builder.build ();solrquery query = new solrquery (); Query.set ("Q", "title: Computer Science and Technology 1495013922355"); queryresponse response = solrclient.query (query);solrdocumentlist list = Response.getresults ();solrclient.commit ();System. out. println ("Number of matches:"+list.getnumfound ()); Iterator ITR = List.iterator ();while (Itr.hasnext ()) { solrdocument solrdocument = (solrdocument) itr.next ();Object id = solrdocument.getfieldvalue ("id"); System. out. println (Id.tostring ()); Object title = Solrdocument.getfieldvalue ("title"); System. out. println (Title.tostring ()); }

This is all done. The above is only the most basic use of the configuration, for the Chinese word or stay in the most primitive of every Chinese as a word segmentation algorithm . This is not desirable to compare violence, need to replace the corresponding Chinese word breaker. a few common commands:start:solr start Specify port start:solr Start- p 8984 Stop SOLR:solr stop- p 8983 Delete the specified core file : SOLR Delete- c corename Create core:SOLR Create- c corename SOLR Status View:solr StatusReference Blog: http://blog.csdn.net/lxl631/article/details/52597134

Apache SOLR (i)

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.