Subversion Repositories SmartDukaan

Rev

Rev 26581 | Rev 26736 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26581 Rev 26606
Line 3... Line 3...
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.HashMap;
4
import java.util.HashMap;
5
import java.util.List;
5
import java.util.List;
6
import java.util.Map;
6
import java.util.Map;
7
 
7
 
8
import javax.servlet.http.HttpServletRequest;
-
 
9
 
-
 
10
import org.apache.commons.lang3.StringUtils;
8
import org.apache.commons.lang3.StringUtils;
11
import org.apache.http.conn.HttpHostConnectException;
9
import org.apache.http.conn.HttpHostConnectException;
12
import org.json.JSONArray;
10
import org.json.JSONArray;
13
import org.json.JSONObject;
11
import org.json.JSONObject;
14
import org.springframework.stereotype.Service;
12
import org.springframework.stereotype.Service;
Line 17... Line 15...
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
15
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.web.client.RestClient;
16
import com.spice.profitmandi.common.web.client.RestClient;
19
 
17
 
20
@Service("solrServiceCommon")
18
@Service("solrServiceCommon")
21
public class SolrService {
19
public class SolrService {
22
	public String getContent( String queryTerm) throws Exception {
20
	public String getContent(String queryTerm) throws Exception {
23
		RestClient rc = new RestClient();
21
		RestClient rc = new RestClient();
24
		Map<String, String> params = new HashMap<>();
22
		Map<String, String> params = new HashMap<>();
25
		List<String> mandatoryQ = new ArrayList<>();
23
		List<String> mandatoryQ = new ArrayList<>();
26
		if (queryTerm != null && !queryTerm.equals("null")) {
24
		if (queryTerm != null && !queryTerm.equals("null")) {
27
			mandatoryQ.add(String.format("+(%s)", queryTerm));
25
			mandatoryQ.add(String.format("+(%s)", queryTerm));
Line 45... Line 43...
45
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
43
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
46
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
44
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
47
		return docs.toString();
45
		return docs.toString();
48
	}
46
	}
49
 
47
 
-
 
48
	public Map<Integer, JSONObject> getContentByCatalogIds(List<Integer> catalogIds) throws Exception {
-
 
49
		RestClient rc = new RestClient();
-
 
50
		Map<Integer, JSONObject> documentMap = new HashMap<>();
-
 
51
		Map<String, String> params = new HashMap<>();
-
 
52
		params.put("q", "catalogId_i:" + StringUtils.join(catalogIds, " "));
-
 
53
		params.put("fl", "*");
-
 
54
		params.put("start", String.valueOf(0));
-
 
55
		params.put("rows", String.valueOf(50));
-
 
56
		params.put("wt", "json");
-
 
57
		String response = null;
-
 
58
		try {
-
 
59
			response = rc.get(SchemeType.HTTP, "192.168.179.131", 8984, "solr/demo/select", params);
-
 
60
		} catch (HttpHostConnectException e) {
-
 
61
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
-
 
62
		}
-
 
63
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
-
 
64
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
-
 
65
		for (int i = 0; i < docs.length(); i++) {
-
 
66
			JSONObject doc = docs.getJSONObject(i);
-
 
67
			documentMap.put(doc.getInt("catalogId_i"), doc);
-
 
68
		}
-
 
69
		return documentMap;
-
 
70
	}
-
 
71
 
50
}
72
}