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.Http2SolrClient;
11 import org.springframework.beans.factory.annotation.Value;
12 import org.springframework.stereotype.Service;
13
14 @Service
15 public class SolrService {
16 @Value("${tailormap-api.solr-url}")
17 private String solrUrl;
18
19 @Value("${tailormap-api.solr-core-name:tailormap}")
20 private String solrCoreName;
21
22 @Value("${tailormap-api.solr-connection-timeout-seconds:60}")
23 private int solrConnectionTimeout;
24
25 @Value("${tailormap-api.solr-request-timeout-seconds:240}")
26 private int solrRequestTimeout;
27
28 @Value("${tailormap-api.solr-idle-timeout-seconds:10}")
29 private int solrIdleTimeout;
30
31
32
33
34
35
36 public SolrClient getSolrClientForIndexing() {
37 return new Http2SolrClient.Builder(this.solrUrl + this.solrCoreName)
38 .withFollowRedirects(true)
39 .withConnectionTimeout(solrConnectionTimeout, TimeUnit.SECONDS)
40 .withRequestTimeout(solrRequestTimeout, TimeUnit.SECONDS)
41
42
43
44 .withIdleTimeout(solrIdleTimeout, TimeUnit.SECONDS)
45 .build();
46 }
47
48
49
50
51
52
53 public SolrClient getSolrClientForSearching() {
54 return new Http2SolrClient.Builder(this.solrUrl + this.solrCoreName)
55 .withConnectionTimeout(solrConnectionTimeout, TimeUnit.SECONDS)
56 .withFollowRedirects(true)
57 .build();
58 }
59
60 public void setSolrUrl(String solrUrl) {
61 this.solrUrl = solrUrl;
62 }
63 }