In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to achieve indexing, query, deletion, spell checking and other functions in java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Use java to operate solr
As mentioned earlier, many operations on solr are operated directly on the page. In actual work, we must use java to operate. Here let's take a look at how to use java to operate solr.
Solr provides solrj to use java to manipulate solr,SolrJ, which encapsulates the httpClient method to manipulate the API of solr. First add maven dependencies
Org.apache.solr
Solr-solrj
4.10.4
Also add junit4's maven dependency
Junit
Junit
4.12
Query query
Now you can write the code and create a new testSolr class
An error was found during execution because the package of common-logging was missing. Add the corresponding maven dependency.
Commons-logging
Commons-logging
1.1.1
In this way, the data in the index database collection1 can be printed out, because the query condition is *: *
You should pay attention to this baseurl. By default, if you do not need to specify to manipulate the data in collection1, the index library collection1 will be operated by default.
So the effect of the two baseurl above is the same.
Index index
Using the add method, you can add a piece of data to the solr.
Index by annotated method
In practical work, it is very troublesome to set up a property when building an index, generally using an object directly, which is very convenient to use.
First of all, create an entity class, the main note that the field inside to add a note, if not added, then solr is not recognized.
This allows the object to be indexed in solr.
Delete index delete
It can be deleted according to ID or according to query conditions.
Spell check spellcheck
Set the handler of the query, modify it to / spell, and get the query result. If the query result is 0, it means there is no query result. It may be that the query keyword entered is incorrect, so that you can get the spelling check response according to the getspellcheckresponse method. According to some methods of this response, you can get the recommended results.
The suggested results can be obtained in the following ways. In this case, you get the results from collation.
Or get the suggested results according to the following methods. In this case, you get the results from suggestion.
Both of the above methods can get the results of the suggested spelling.
This is the end of the content of "how to implement indexing, query, deletion, spell checking and other functions in java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.