| Line 173... |
Line 173... |
| 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 |
/**
|
177 |
/**
|
| 178 |
* Category facet over the curated hot-deal models: which categoryId_i values are
|
178 |
* Category facet over the hot-deal models: which categoryId_i values are present (and
|
| 179 |
* present (and how many models each) among the docs the hot-deal listing can show.
|
179 |
* how many models each) among the docs the hot-deal listing can show. Drives the
|
| 180 |
* Drives the page's category filter chips.
|
180 |
* page's category filter chips.
|
| 181 |
*/
|
181 |
*/
|
| 182 |
public Map<Integer, Integer> getHotDealCategoryFacet(List<Integer> hotDealCatalogIds) throws Exception {
|
182 |
public Map<Integer, Integer> getHotDealCategoryFacet(List<Integer> hotDealCatalogIds) throws Exception {
|
| 183 |
Map<Integer, Integer> counts = new LinkedHashMap<>();
|
183 |
Map<Integer, Integer> counts = new LinkedHashMap<>();
|
| - |
|
184 |
for (Map.Entry<String, Integer> bucket : hotDealFacet(hotDealCatalogIds, "categoryId_i").entrySet()) {
|
| - |
|
185 |
counts.put(Integer.parseInt(bucket.getKey()), bucket.getValue());
|
| - |
|
186 |
}
|
| - |
|
187 |
return counts;
|
| - |
|
188 |
}
|
| - |
|
189 |
|
| - |
|
190 |
/**
|
| - |
|
191 |
* Brand facet over the hot-deal models, driving the page's brand chips.
|
| - |
|
192 |
*
|
| - |
|
193 |
* <p>Facets on oem_brand_s, NOT brand_ss. Every hot-deal doc reads "Hot Deal" in
|
| - |
|
194 |
* brand_ss - that is the whole point of the brand - so faceting there would yield a
|
| - |
|
195 |
* single useless bucket. oem_brand_s carries the brand the SKU had before the move
|
| - |
|
196 |
* (Samsung, OnePlus, ...), which is what a partner actually wants to narrow by. It is
|
| - |
|
197 |
* surfaced to partners as plain "Brand"; "OEM" is internal vocabulary.
|
| - |
|
198 |
*/
|
| - |
|
199 |
public Map<String, Integer> getHotDealBrandFacet(List<Integer> hotDealCatalogIds) throws Exception {
|
| - |
|
200 |
return hotDealFacet(hotDealCatalogIds, "oem_brand_s");
|
| - |
|
201 |
}
|
| - |
|
202 |
|
| - |
|
203 |
/**
|
| - |
|
204 |
* One facet query over the hot-deal doc set, keyed by raw bucket value. Shared by the
|
| - |
|
205 |
* category and brand facets, which differ only in the field they count.
|
| - |
|
206 |
*/
|
| - |
|
207 |
private Map<String, Integer> hotDealFacet(List<Integer> hotDealCatalogIds, String facetField)
|
| - |
|
208 |
throws Exception {
|
| - |
|
209 |
Map<String, Integer> counts = new LinkedHashMap<>();
|
| 184 |
if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()) {
|
210 |
if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()) {
|
| 185 |
return counts;
|
211 |
return counts;
|
| 186 |
}
|
212 |
}
|
| 187 |
String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
|
213 |
String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
|
| 188 |
.collect(Collectors.joining(" OR "));
|
214 |
.collect(Collectors.joining(" OR "));
|
| 189 |
Map<String, String> params = new HashMap<>();
|
215 |
Map<String, String> params = new HashMap<>();
|
| 190 |
params.put("q", "+id:(" + idClause + ") +show_default_b:true +eol_no_stock_b:false");
|
216 |
params.put("q", "+id:(" + idClause + ") +show_default_b:true +eol_no_stock_b:false");
|
| 191 |
params.put("rows", "0");
|
217 |
params.put("rows", "0");
|
| 192 |
params.put("facet", "true");
|
218 |
params.put("facet", "true");
|
| 193 |
params.put("facet.field", "categoryId_i");
|
219 |
params.put("facet.field", facetField);
|
| 194 |
params.put("facet.mincount", "1");
|
220 |
params.put("facet.mincount", "1");
|
| 195 |
params.put("wt", "json");
|
221 |
params.put("wt", "json");
|
| 196 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
222 |
String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 197 |
JSONArray buckets = new JSONObject(response).getJSONObject("facet_counts")
|
223 |
JSONArray buckets = new JSONObject(response).getJSONObject("facet_counts")
|
| 198 |
.getJSONObject("facet_fields").getJSONArray("categoryId_i");
|
224 |
.getJSONObject("facet_fields").getJSONArray(facetField);
|
| 199 |
for (int i = 0; i + 1 < buckets.length(); i += 2) {
|
225 |
for (int i = 0; i + 1 < buckets.length(); i += 2) {
|
| 200 |
counts.put(Integer.parseInt(buckets.getString(i)), buckets.getInt(i + 1));
|
226 |
counts.put(buckets.getString(i), buckets.getInt(i + 1));
|
| 201 |
}
|
227 |
}
|
| 202 |
return counts;
|
228 |
return counts;
|
| 203 |
}
|
229 |
}
|
| 204 |
|
230 |
|
| 205 |
public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
|
231 |
public JSONArray getSolrDocs(String queryTerm, String categoryId, int offset, int limit, String sort,
|
| Line 234... |
Line 260... |
| 234 |
if (queryTerm == null || queryTerm.equals("null")) {
|
260 |
if (queryTerm == null || queryTerm.equals("null")) {
|
| 235 |
queryTerm = "";
|
261 |
queryTerm = "";
|
| 236 |
} else {
|
262 |
} else {
|
| 237 |
queryTerm = "(" + queryTerm + ")";
|
263 |
queryTerm = "(" + queryTerm + ")";
|
| 238 |
}
|
264 |
}
|
| - |
|
265 |
// True when this query is scoped to hot deals by EITHER route below. The brand
|
| - |
|
266 |
// filter keys off this rather than the hotDeal flag alone, because the caller that
|
| - |
|
267 |
// resolves the catalog ids itself passes hotDeal = false - and that listing still
|
| - |
|
268 |
// needs its brand chips routed to oem_brand_s.
|
| - |
|
269 |
boolean hotDealScoped = hotDeal || (hotDealCatalogIds != null && !hotDealCatalogIds.isEmpty());
|
| - |
|
270 |
|
| 239 |
if (hotDealCatalogIds != null && !hotDealCatalogIds.isEmpty()) {
|
271 |
if (hotDealCatalogIds != null && !hotDealCatalogIds.isEmpty()) {
|
| 240 |
// Caller already resolved the active model_hot_deal set: restrict parents to
|
272 |
// Caller already resolved the hot-deal set from the brand: restrict parents to
|
| 241 |
// those models; items stay the normal active set
|
273 |
// those models; items stay the normal active set
|
| 242 |
String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
|
274 |
String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
|
| 243 |
.collect(java.util.stream.Collectors.joining(" OR "));
|
275 |
.collect(java.util.stream.Collectors.joining(" OR "));
|
| 244 |
parentFilter.add("id:(" + idClause + ")");
|
276 |
parentFilter.add("id:(" + idClause + ")");
|
| 245 |
childFilter.add("active_b:true");
|
277 |
childFilter.add("active_b:true");
|
| 246 |
} else if (hotDeal) {
|
278 |
} else if (hotDeal) {
|
| 247 |
// hot_deal_b is derived from catalog.model_hot_deal at index time (FofoSolr)
|
279 |
// hot_deal_b is derived from the SKU's brand at index time (FofoSolr)
|
| 248 |
childFilter.add("hot_deal_b:true");
|
280 |
childFilter.add("hot_deal_b:true");
|
| 249 |
} else {
|
281 |
} else {
|
| 250 |
childFilter.add("active_b:true");
|
282 |
childFilter.add("active_b:true");
|
| 251 |
}
|
283 |
}
|
| 252 |
if (subCategoryId != 0) {
|
284 |
if (subCategoryId != 0) {
|
| Line 255... |
Line 287... |
| 255 |
|
287 |
|
| 256 |
if(eol_filter){
|
288 |
if(eol_filter){
|
| 257 |
parentFilter.add("eol_no_stock_b:false");
|
289 |
parentFilter.add("eol_no_stock_b:false");
|
| 258 |
}
|
290 |
}
|
| 259 |
if (StringUtils.isNotBlank(brand)) {
|
291 |
if (StringUtils.isNotBlank(brand)) {
|
| - |
|
292 |
// Inside the hot-deal listing the brand chips carry the ORIGINAL brand, which
|
| - |
|
293 |
// lives in oem_brand_s - every one of those docs reads "Hot Deal" in brand_ss,
|
| - |
|
294 |
// so filtering there would match nothing.
|
| - |
|
295 |
String brandField = hotDealScoped ? "oem_brand_s" : "brand_ss";
|
| 260 |
parentFilter.add("brand_ss:" + "\\\"" + brand + "\\\"");
|
296 |
parentFilter.add(brandField + ":" + "\\\"" + brand + "\\\"");
|
| 261 |
}
|
297 |
}
|
| 262 |
if (queryTerm == "") {
|
298 |
if (queryTerm == "") {
|
| 263 |
params.put("sort", (sort == "" ? "" : sort + ", ") + "create_s desc");
|
299 |
params.put("sort", (sort == "" ? "" : sort + ", ") + "create_s desc");
|
| 264 |
} else {
|
300 |
} else {
|
| 265 |
parentFilter.addAll(Arrays.asList(queryTerm.split(" ")));
|
301 |
parentFilter.addAll(Arrays.asList(queryTerm.split(" ")));
|