Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to operate solr addition, deletion, modification and search in SolrJ

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to operate solr additions, deletions, modifications and queries in SolrJ. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Features of Solr include:

Advanced full-text search function

Optimization designed for high-throughput network traffic

Standards based on open interfaces (XML and HTTP)

Integrated HTML management interface

Scalability-ability to effectively copy to another Solr search server

Use XML configuration for flexibility and adaptation

Extensible plug-in system

/ / paging query / / create SolrServer object for solr HttpSolrServer server = new HttpSolrServer (url); / / timeout unit server.setConnectionTimeout (timeout) for connecting to solr server; / / whether trace redirection default false server.setFollowRedirects (followRedirects) is allowed; / / whether compression server.setAllowCompression (allowCompression) is allowed / / maximum number of reconnections server.setMaxRetries (maxRetries); / / create query object SolrQuery query = communitySolrHandler.createQuery (pagination); public SolrQuery createQuery (Pagination pagination) {SolrQuery query = new SolrQuery (); CommunitySolrField k = pagination.getDto (); String value = k.getShortPy (); StringBuilder sb = new StringBuilder () / / stitching query criteria if (! CollectionUtils.isEmpty (k.getRegionIds () {for (String regionId:k.getRegionIds ()) {sb.append ("regionId:" + regionId);}} if (! CollectionUtils.isEmpty (k.getProjectIds () {for (String projectId:k.getProjectIds ()) {sb.append ("projectId:" + projectId) }} query.setQuery (sb.toString ()); / / filter the following conditions if (StringUtils.hasText (value)) {if (ToolUtils.matcherZh (value)) {query.addFilterQuery ("communityName:" + value);} else {query.addFilterQuery ("shortPiny:" + value.toLowerCase () + "*") }} / / return result int start = ToolUtils.start (pagination.getPageNo (), pagination.getPageSize ()); / / query query.setStart (start); query.setRows (pagination.getPageSize ()); return query Generally, this code uses scheduled tasks to run ConcurrentUpdateSolrServer server = new ConcurrentUpdateSolrServer (solrJSearchClient.getUrl () + SolrTable.community.toString (), solrJSearchClient.getQueueSize (), solrJSearchClient.getThreadCount ()); List list = communityDao.findAllCommunitySolr (); if (CollectionUtils.isEmpty (list)) {return;} List ids = new ArrayList (); List docs = new ArrayList (); SolrInputDocument doc HanZi hanZi; for (CommunityDto communityDto:list) {doc = new SolrInputDocument (); hanZi = new HanZi (communityDto.getName ()); doc.addField ("id", communityDto.getId ()); doc.addField ("communityName", communityDto.getName ()); doc.addField ("piny", communityDto.getPiny ()) Doc.addField ("shortPiny", hanZi.getPinYinHeadChar ()); doc.addField ("sortDefault", communityDto.getSortDefault ()); doc.addField ("regionId", communityDto.getDicRegionId ()); doc.addField ("projectId", communityDto.getProjectId ()); docs.add (doc); ids.add (communityDto.getId ()) } try {/ / first delete server.deleteById (ids); server.commit (); / then add / update index server.add (docs); / / optimize server.optimize (); server.commit () } catch (Exception e) {e.printStackTrace ();} after reading the above, do you have any further understanding of how to add, delete, modify and check solr in SolrJ? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report