1
2
3
4
5
6 package org.tailormap.api.solr;
7
8 import java.util.concurrent.TimeUnit;
9 import org.apache.solr.client.solrj.SolrClient;
10 import org.apache.solr.client.solrj.impl.ConcurrentUpdateHttp2SolrClient;
11 import org.apache.solr.client.solrj.impl.Http2SolrClient;
12 import org.springframework.beans.factory.annotation.Value;
13 import org.springframework.stereotype.Service;
14
15 @Service
16 public class SolrService {
17 @Value("${tailormap-api.solr-url}")
18 private String solrUrl;
19
20 @Value("${tailormap-api.solr-core-name:tailormap}")
21 private String solrCoreName;
22
23
24
25
26
27
28 public SolrClient getSolrClientForIndexing() {
29 return new ConcurrentUpdateHttp2SolrClient.Builder(
30 this.solrUrl + this.solrCoreName,
31 new Http2SolrClient.Builder()
32 .withFollowRedirects(true)
33 .withConnectionTimeout(10000, TimeUnit.MILLISECONDS)
34 .withRequestTimeout(60000, TimeUnit.MILLISECONDS)
35 .build())
36 .withQueueSize(SolrHelper.SOLR_BATCH_SIZE * 2)
37 .withThreadCount(10)
38 .build();
39 }
40
41
42
43
44
45
46 public SolrClient getSolrClientForSearching() {
47 return new Http2SolrClient.Builder(this.solrUrl + this.solrCoreName)
48 .withConnectionTimeout(10, TimeUnit.SECONDS)
49 .withFollowRedirects(true)
50 .build();
51 }
52
53 public void setSolrUrl(String solrUrl) {
54 this.solrUrl = solrUrl;
55 }
56 }