| Line 7... |
Line 7... |
| 7 |
|
7 |
|
| 8 |
import org.apache.commons.lang3.StringUtils;
|
8 |
import org.apache.commons.lang3.StringUtils;
|
| 9 |
import org.apache.http.conn.HttpHostConnectException;
|
9 |
import org.apache.http.conn.HttpHostConnectException;
|
| 10 |
import org.json.JSONArray;
|
10 |
import org.json.JSONArray;
|
| 11 |
import org.json.JSONObject;
|
11 |
import org.json.JSONObject;
|
| - |
|
12 |
import org.springframework.beans.factory.annotation.Value;
|
| 12 |
import org.springframework.stereotype.Service;
|
13 |
import org.springframework.stereotype.Service;
|
| 13 |
|
14 |
|
| 14 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
15 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 15 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 16 |
import com.spice.profitmandi.common.web.client.RestClient;
|
17 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 17 |
|
18 |
|
| 18 |
@Service("solrServiceCommon")
|
19 |
@Service("solrServiceCommon")
|
| 19 |
public class SolrService {
|
20 |
public class SolrService {
|
| - |
|
21 |
|
| - |
|
22 |
@Value("${new.solr.url}")
|
| - |
|
23 |
private String solrUrl;
|
| 20 |
public String getContent(String queryTerm) throws Exception {
|
24 |
public String getContent(String queryTerm) throws Exception {
|
| 21 |
RestClient rc = new RestClient();
|
25 |
RestClient rc = new RestClient();
|
| 22 |
Map<String, String> params = new HashMap<>();
|
26 |
Map<String, String> params = new HashMap<>();
|
| 23 |
List<String> mandatoryQ = new ArrayList<>();
|
27 |
List<String> mandatoryQ = new ArrayList<>();
|
| 24 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
28 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
| Line 34... |
Line 38... |
| 34 |
params.put("start", String.valueOf(0));
|
38 |
params.put("start", String.valueOf(0));
|
| 35 |
params.put("rows", String.valueOf(20));
|
39 |
params.put("rows", String.valueOf(20));
|
| 36 |
params.put("wt", "json");
|
40 |
params.put("wt", "json");
|
| 37 |
String response = null;
|
41 |
String response = null;
|
| 38 |
try {
|
42 |
try {
|
| 39 |
response = rc.get(SchemeType.HTTP, "192.168.179.131", 8984, "solr/demo/select", params);
|
43 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 40 |
} catch (HttpHostConnectException e) {
|
44 |
} catch (HttpHostConnectException e) {
|
| 41 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
45 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 42 |
}
|
46 |
}
|
| 43 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
47 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 44 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
48 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
| Line 54... |
Line 58... |
| 54 |
params.put("start", String.valueOf(0));
|
58 |
params.put("start", String.valueOf(0));
|
| 55 |
params.put("rows", String.valueOf(50));
|
59 |
params.put("rows", String.valueOf(50));
|
| 56 |
params.put("wt", "json");
|
60 |
params.put("wt", "json");
|
| 57 |
String response = null;
|
61 |
String response = null;
|
| 58 |
try {
|
62 |
try {
|
| 59 |
response = rc.get(SchemeType.HTTP, "192.168.179.131", 8984, "solr/demo/select", params);
|
63 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 60 |
} catch (HttpHostConnectException e) {
|
64 |
} catch (HttpHostConnectException e) {
|
| 61 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
65 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
| 62 |
}
|
66 |
}
|
| 63 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
67 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
| 64 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
68 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|