Java Operation SOLR implements index, query, delete, spell check and other functions

Source: Internet
Author: User

Using Java operations solr  Many of the operations on SOLR are done directly on the page, and the actual work must be done using Java, Here we look at how Java is used to manipulate SOLRSOLR provides SOLRJ to use Java operations SOLR,SOLRJ is to encapsulate the HttpClient method to manipulate the SOLR API. First add maven dependency <dependency>       <groupId>org.apache.solr</groupId>       <artifactId>solr-solrj</artifactId>       <version>4.10.4 </version></dependency>  add junit4 maven dependencies <dependency>       < groupid>junit</groupid>       <artifactId>junit</artifactId>        <version>4.12</version></dependency>  Query queries you can write the code below and create a new TESTSOLR class,  The error is found when executing, because of the lack of common-logging package, add corresponding maven dependency <dependency>               <groupId>commons-logging</groupId>               <artifactId>commons-logging</artifactId>              <version>1.1.1</version></dependency>   This can be collection1 this index database inside the data printed out, because the query condition is *:*  in this to pay attention to this baseurl, by default, if the operation Collection1 the data inside the words do not need to specify it, The Collection1 Index Library is manipulated by default. So the effect of the above two BaseURL is the same.   Index using the Add method, you can add a piece of data to SOLR.   Annotations How to build an index in the actual work, if it is difficult to set up a property for a property at the time of indexing, it is usually a direct use of an object, which is very convenient to use. First, create an entity class, focusing on the field in which you want to add an annotation, and if you don't add it, SOLR is not recognized.   This allows the object to be indexed in SOLR.   Deleting an index delete  can be deleted by ID or by query criteria.    spell Check spellcheck set the handler of the query, modify it to/spell, get the query results, if the query result is 0, then there is no query to the result, may be the input query keyword has an error, This allows the response of the spelling checker to be obtained based on the Getspellcheckresponse method, and the suggested results can be obtained based on some methods of this response. You can obtain the suggested results as follows. In this is the result obtained from the collation. Or get the suggested results based on the following method. In this is the result obtained from the suggestion.   The results of the suggested spellings are available in both of the above ways. For more highlights, please pay attention to: http://bbs.superwu.cn attention to Superman academy QR Code:

Java Operations SOLR implements indexes, queries, deletions, spell checking, and other functions

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.