| Line 179... |
Line 179... |
| 179 |
* how many models each) among the docs the hot-deal listing can show. Drives the
|
179 |
* how many models each) among the docs the hot-deal listing can show. Drives the
|
| 180 |
* 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
|
| 184 |
for (Map.Entry<String, Integer> bucket : hotDealFacet(hotDealCatalogIds, "categoryId_i").entrySet()) {
|
185 |
: hotDealFacet(hotDealCatalogIds, "categoryId_i", null).entrySet()) {
|
| 185 |
counts.put(Integer.parseInt(bucket.getKey()), bucket.getValue());
|
186 |
counts.put(Integer.parseInt(bucket.getKey()), bucket.getValue());
|
| 186 |
}
|
187 |
}
|
| 187 |
return counts;
|
188 |
return counts;
|
| 188 |
}
|
189 |
}
|
| 189 |
|
190 |
|
| Line 194... |
Line 195... |
| 194 |
* brand_ss - that is the whole point of the brand - so faceting there would yield a
|
195 |
* 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 |
* 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 |
* (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 |
* surfaced to partners as plain "Brand"; "OEM" is internal vocabulary.
|
| 198 |
*/
|
199 |
*/
|
| - |
|
200 |
/**
|
| - |
|
201 |
* @param categoryId when set, counts only models in that category, so the chips match
|
| - |
|
202 |
* the tab the partner is standing on. Without it the row is global:
|
| - |
|
203 |
* the LED TVs tab would offer Samsung and Vivo chips even though
|
| - |
|
204 |
* neither has a hot-deal TV, and tapping one returns nothing.
|
| - |
|
205 |
*/
|
| 199 |
public Map<String, Integer> getHotDealBrandFacet(List<Integer> hotDealCatalogIds) throws Exception {
|
206 |
public Map<String, Integer> getHotDealBrandFacet(List<Integer> hotDealCatalogIds, Integer categoryId)
|
| - |
|
207 |
throws Exception {
|
| 200 |
return hotDealFacet(hotDealCatalogIds, "oem_brand_s");
|
208 |
return hotDealFacet(hotDealCatalogIds, "oem_brand_s", categoryId);
|
| 201 |
}
|
209 |
}
|
| 202 |
|
210 |
|
| 203 |
/**
|
211 |
/**
|
| 204 |
* One facet query over the hot-deal doc set, keyed by raw bucket value. Shared by the
|
212 |
* 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.
|
213 |
* category and brand facets, which differ only in the field they count and whether
|
| - |
|
214 |
* they narrow to a category.
|
| 206 |
*/
|
215 |
*/
|
| 207 |
private Map<String, Integer> hotDealFacet(List<Integer> hotDealCatalogIds, String facetField)
|
216 |
private Map<String, Integer> hotDealFacet(List<Integer> hotDealCatalogIds, String facetField,
|
| 208 |
throws Exception {
|
217 |
Integer categoryId) throws Exception {
|
| 209 |
Map<String, Integer> counts = new LinkedHashMap<>();
|
218 |
Map<String, Integer> counts = new LinkedHashMap<>();
|
| 210 |
if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()) {
|
219 |
if (hotDealCatalogIds == null || hotDealCatalogIds.isEmpty()) {
|
| 211 |
return counts;
|
220 |
return counts;
|
| 212 |
}
|
221 |
}
|
| 213 |
String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
|
222 |
String idClause = hotDealCatalogIds.stream().map(x -> "catalog" + x)
|
| 214 |
.collect(Collectors.joining(" OR "));
|
223 |
.collect(Collectors.joining(" OR "));
|
| - |
|
224 |
// categoryId_i lives on the parent (catalog) doc, same as the id clause, so it
|
| - |
|
225 |
// narrows the facet without needing a child-document join.
|
| - |
|
226 |
String categoryClause = categoryId == null || categoryId <= 0
|
| - |
|
227 |
? "" : " +categoryId_i:" + categoryId;
|
| 215 |
Map<String, String> params = new HashMap<>();
|
228 |
Map<String, String> params = new HashMap<>();
|
| 216 |
params.put("q", "+id:(" + idClause + ") +show_default_b:true +eol_no_stock_b:false");
|
229 |
params.put("q", "+id:(" + idClause + ") +show_default_b:true +eol_no_stock_b:false"
|
| - |
|
230 |
+ categoryClause);
|
| 217 |
params.put("rows", "0");
|
231 |
params.put("rows", "0");
|
| 218 |
params.put("facet", "true");
|
232 |
params.put("facet", "true");
|
| 219 |
params.put("facet.field", facetField);
|
233 |
params.put("facet.field", facetField);
|
| 220 |
params.put("facet.mincount", "1");
|
234 |
params.put("facet.mincount", "1");
|
| 221 |
params.put("wt", "json");
|
235 |
params.put("wt", "json");
|