Subversion Repositories SmartDukaan

Rev

Rev 37253 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37253 Rev 37259
Line 172... Line 172...
172
		}
172
		}
173
		return "-brand_ss:(" + excludeBrands.stream().map(x -> "\"" + x + "\"").collect(Collectors.joining(" OR "))
173
		return "-brand_ss:(" + excludeBrands.stream().map(x -> "\"" + x + "\"").collect(Collectors.joining(" OR "))
174
				+ ")";
174
				+ ")";
175
	}
175
	}
176
 
176
 
-
 
177
	/**
-
 
178
	 * Category facet over the curated hot-deal models: which categoryId_i values are
-
 
179
	 * present (and how many models each) among the docs the hot-deal listing can show.
-
 
180
	 * Drives the page's category filter chips.
-
 
181
	 */
-
 
182
	public Map<Integer, Integer> getHotDealCategoryFacet(List<Integer> hotDealCatalogIds) throws Exception {
-
 
183
		Map<Integer, Integer> counts = new LinkedHashMap<>();
-
 
184
		if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()) {
-
 
185
			return counts;
-
 
186
		}
-
 
187
		String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
-
 
188
				.collect(Collectors.joining(" OR "));
-
 
189
		Map<String, String> params = new HashMap<>();
-
 
190
		params.put("q", "+id:(" + idClause + ") +show_default_b:true +eol_no_stock_b:false");
-
 
191
		params.put("rows", "0");
-
 
192
		params.put("facet", "true");
-
 
193
		params.put("facet.field", "categoryId_i");
-
 
194
		params.put("facet.mincount", "1");
-
 
195
		params.put("wt", "json");
-
 
196
		String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
-
 
197
		JSONArray buckets = new JSONObject(response).getJSONObject("facet_counts")
-
 
198
				.getJSONObject("facet_fields").getJSONArray("categoryId_i");
-
 
199
		for (int i = 0; i + 1 < buckets.length(); i += 2) {
-
 
200
			counts.put(Integer.parseInt(buckets.getString(i)), buckets.getInt(i + 1));
-
 
201
		}
-
 
202
		return counts;
-
 
203
	}
-
 
204
 
177
	public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
205
	public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
178
			String brand, int subCategoryId, boolean hotDeal, boolean group, boolean eol_filter) throws Throwable {
206
			String brand, int subCategoryId, boolean hotDeal, boolean group, boolean eol_filter) throws Throwable {
179
		return this.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group,
207
		return this.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group,
180
				eol_filter, null);
208
				eol_filter, null);
181
	}
209
	}
Line 189... Line 217...
189
 
217
 
190
	public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
218
	public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
191
			String brand, int subCategoryId, boolean hotDeal, boolean group, boolean eol_filter,
219
			String brand, int subCategoryId, boolean hotDeal, boolean group, boolean eol_filter,
192
			List<String> excludeBrands, List<Integer> hotDealCatalogIds) throws Throwable {
220
			List<String> excludeBrands, List<Integer> hotDealCatalogIds) throws Throwable {
193
		List<String> parentFilter = new ArrayList<>();
221
		List<String> parentFilter = new ArrayList<>();
-
 
222
		// Hot-deal listings are cross-category by default (the curated catalogId filter
-
 
223
		// is the scope); categoryId is applied there only when the caller explicitly
-
 
224
		// passes one (the page's category filter chips)
194
		if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()) {
225
		if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()
-
 
226
				|| (categoryId != null && !categoryId.trim().isEmpty())) {
195
			parentFilter.add("categoryId_i:" + categoryId);
227
			parentFilter.add("categoryId_i:" + categoryId);
196
		}
228
		}
197
		// hot-deal listings are cross-category: the curated catalogId filter below is
-
 
198
		// the scope, so no category gate (deals span phones/accessories/LEDs)
-
 
199
		parentFilter.add("show_default_b:true");
229
		parentFilter.add("show_default_b:true");
200
		List<String> childFilter = new ArrayList<>();
230
		List<String> childFilter = new ArrayList<>();
201
		childFilter.add("itemId_i:*");
231
		childFilter.add("itemId_i:*");
202
 
232
 
203
		Map<String, String> params = new HashMap<>();
233
		Map<String, String> params = new HashMap<>();
Line 205... Line 235...
205
			queryTerm = "";
235
			queryTerm = "";
206
		} else {
236
		} else {
207
			queryTerm = "(" + queryTerm + ")";
237
			queryTerm = "(" + queryTerm + ")";
208
		}
238
		}
209
		if (hotDealCatalogIds != null && !hotDealCatalogIds.isEmpty()) {
239
		if (hotDealCatalogIds != null && !hotDealCatalogIds.isEmpty()) {
210
			// New model_hot_deal-driven hot deals: restrict parents to the active deal
240
			// Caller already resolved the active model_hot_deal set: restrict parents to
211
			// models; items stay the normal active set (old hot_deal_b flag not used)
241
			// those models; items stay the normal active set
212
			String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
242
			String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
213
					.collect(java.util.stream.Collectors.joining(" OR "));
243
					.collect(java.util.stream.Collectors.joining(" OR "));
214
			parentFilter.add("id:(" + idClause + ")");
244
			parentFilter.add("id:(" + idClause + ")");
215
			childFilter.add("active_b:true");
245
			childFilter.add("active_b:true");
216
		} else if (hotDeal) {
246
		} else if (hotDeal) {
-
 
247
			// hot_deal_b is derived from catalog.model_hot_deal at index time (FofoSolr)
217
			childFilter.add("hot_deal_b:true");
248
			childFilter.add("hot_deal_b:true");
218
		} else {
249
		} else {
219
			childFilter.add("active_b:true");
250
			childFilter.add("active_b:true");
220
		}
251
		}
221
		if (subCategoryId != 0) {
252
		if (subCategoryId != 0) {