Subversion Repositories SmartDukaan

Rev

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

Rev 33573 Rev 34023
Line 101... Line 101...
101
	}
101
	}
102
 
102
 
103
	// This method is the used to pull docs based on search and shall be used
103
	// This method is the used to pull docs based on search and shall be used
104
	// interchangably for both the things
104
	// interchangably for both the things
105
	public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
105
	public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
106
			String brand, int subCategoryId, boolean hotDeal) throws Throwable {
106
			String brand, int subCategoryId, boolean hotDeal, boolean group) throws Throwable {
107
		List<String> parentFilter = new ArrayList<>();
107
		List<String> parentFilter = new ArrayList<>();
108
		parentFilter.add("categoryId_i:" + categoryId);
108
		parentFilter.add("categoryId_i:" + categoryId);
109
		parentFilter.add("show_default_b:true");
109
		parentFilter.add("show_default_b:true");
110
		List<String> childFilter = new ArrayList<>();
110
		List<String> childFilter = new ArrayList<>();
111
		childFilter.add("itemId_i:*");
111
		childFilter.add("itemId_i:*");
Line 138... Line 138...
138
		params.put("fl",
138
		params.put("fl",
139
				String.format("*, [child parentFilter=id:catalog* childFilter=%s]", "\"" + childFilterString + "\""));
139
				String.format("*, [child parentFilter=id:catalog* childFilter=%s]", "\"" + childFilterString + "\""));
140
		params.put("start", String.valueOf(offset));
140
		params.put("start", String.valueOf(offset));
141
		params.put("rows", String.valueOf(limit));
141
		params.put("rows", String.valueOf(limit));
142
		params.put("wt", "json");
142
		params.put("wt", "json");
-
 
143
 
-
 
144
		String groupByField = null;
-
 
145
 
-
 
146
		if (group) {
-
 
147
			groupByField = "superCatalog_s";
-
 
148
			params.put("group", String.valueOf(group));
-
 
149
			params.put("group.field", groupByField);
-
 
150
			params.put("group.limit", "1");
-
 
151
			if (!sort.isEmpty()) {
-
 
152
				params.put("group.sort", sort);
-
 
153
			}
-
 
154
		}
-
 
155
logger.info("groupByField {}", groupByField);
143
		String response = null;
156
		String response = null;
-
 
157
 
144
		try {
158
		try {
145
			response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
159
			response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
146
		} catch (HttpHostConnectException e) {
160
		} catch (HttpHostConnectException e) {
147
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
161
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
148
		}
162
		}
-
 
163
 
149
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
164
		/*JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
150
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
165
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");*/
-
 
166
 
-
 
167
		JSONObject solrResponseJSONObj = new JSONObject(response);
-
 
168
		JSONArray docs;
-
 
169
 
-
 
170
		if (group) {
-
 
171
			logger.info("Reached in if condition {}",groupByField);
-
 
172
			JSONObject grouped = solrResponseJSONObj.getJSONObject("grouped");
-
 
173
			JSONArray groups = grouped.getJSONObject(groupByField).getJSONArray("groups");
-
 
174
 
-
 
175
			docs = new JSONArray();
-
 
176
			for (int i = 0; i < groups.length(); i++) {
-
 
177
				JSONObject groupObj = groups.getJSONObject(i);
-
 
178
				JSONArray groupDocs = groupObj.getJSONObject("doclist").getJSONArray("docs");
-
 
179
				for (int j = 0; j < groupDocs.length(); j++) {
-
 
180
					docs.put(groupDocs.getJSONObject(j));
-
 
181
				}
-
 
182
			}
-
 
183
		} else {
-
 
184
			logger.info("Reached in else condition {}",groupByField);
-
 
185
			docs = solrResponseJSONObj.getJSONObject("response").getJSONArray("docs");
-
 
186
		}
151
 
187
 
152
		return docs;
188
		return docs;
153
	}
189
	}
154
 
190
 
155
}
191
}