| Line 19... |
Line 19... |
| 19 |
|
19 |
|
| 20 |
import org.apache.logging.log4j.LogManager;
|
20 |
import org.apache.logging.log4j.LogManager;
|
| 21 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| 22 |
import org.apache.solr.client.solrj.SolrClient;
|
22 |
import org.apache.solr.client.solrj.SolrClient;
|
| 23 |
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
23 |
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
| 24 |
import org.apache.solr.client.solrj.response.UpdateResponse;
|
24 |
import org.apache.solr.client.solrj.response.schema.SchemaResponse.UpdateResponse;
|
| 25 |
import org.apache.solr.common.SolrInputDocument;
|
25 |
import org.apache.solr.common.SolrInputDocument;
|
| 26 |
import org.json.JSONArray;
|
26 |
import org.json.JSONArray;
|
| 27 |
import org.json.JSONException;
|
27 |
import org.json.JSONException;
|
| 28 |
import org.json.JSONObject;
|
28 |
import org.json.JSONObject;
|
| 29 |
import org.springframework.beans.factory.annotation.Autowired;
|
29 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 30 |
import org.springframework.stereotype.Component;
|
30 |
import org.springframework.stereotype.Component;
|
| 31 |
|
31 |
|
| 32 |
import com.google.gson.Gson;
|
32 |
import com.google.gson.Gson;
|
| 33 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
33 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 34 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
34 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| - |
|
35 |
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
|
| 35 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
36 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 36 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
37 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
38 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
39 |
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
|
| - |
|
40 |
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
|
| 38 |
import com.spice.profitmandi.service.tag.ItemTagModel;
|
41 |
import com.spice.profitmandi.service.tag.ItemTagModel;
|
| 39 |
|
42 |
|
| 40 |
import in.shop2020.model.v1.catalog.status;
|
43 |
import in.shop2020.model.v1.catalog.status;
|
| 41 |
|
44 |
|
| 42 |
@Component
|
45 |
@Component
|
| Line 52... |
Line 55... |
| 52 |
TagRankingRepository tagRankingRepository;
|
55 |
TagRankingRepository tagRankingRepository;
|
| 53 |
|
56 |
|
| 54 |
@Autowired
|
57 |
@Autowired
|
| 55 |
private Mongo contentMongoClient;
|
58 |
private Mongo contentMongoClient;
|
| 56 |
|
59 |
|
| - |
|
60 |
@Autowired
|
| - |
|
61 |
private WebListingRepository webListingRepository;
|
| - |
|
62 |
|
| - |
|
63 |
@Autowired
|
| - |
|
64 |
private WebProductListingRepository webProductListingRepository;
|
| - |
|
65 |
|
| 57 |
private static final Logger logger = LogManager.getLogger(FofoSolr.class);
|
66 |
private static final Logger logger = LogManager.getLogger(FofoSolr.class);
|
| 58 |
|
67 |
|
| 59 |
private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
|
68 |
private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
|
| 60 |
|
69 |
|
| 61 |
String solrPath = "http://localhost:8984/solr/demo";
|
70 |
String solrPath = "http://localhost:8984/solr/demo";
|
| Line 212... |
Line 221... |
| 212 |
}
|
221 |
}
|
| 213 |
return availabilityItemMap;
|
222 |
return availabilityItemMap;
|
| 214 |
|
223 |
|
| 215 |
}
|
224 |
}
|
| 216 |
|
225 |
|
| - |
|
226 |
public Map<Integer, List<String>> getLabels() {
|
| - |
|
227 |
List<String> labels = Arrays.asList("partner-best-sellers", "partner-price-drop", "new-launches");
|
| - |
|
228 |
|
| - |
|
229 |
Map<Integer, String> webListing = webListingRepository.selectByUrls(labels).stream()
|
| - |
|
230 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getUrl()));
|
| - |
|
231 |
|
| - |
|
232 |
Map<Integer, List<WebProductListing>> webProductListingMap = webProductListingRepository
|
| - |
|
233 |
.selectAllByWebListingIds(new ArrayList<>(webListing.keySet())).stream()
|
| - |
|
234 |
.collect(Collectors.groupingBy(x -> x.getWebListingId()));
|
| - |
|
235 |
|
| - |
|
236 |
Map<Integer, List<String>> catalogLabelMap = new HashMap<>();
|
| - |
|
237 |
for (Entry<Integer, List<WebProductListing>> webProductListingEntry : webProductListingMap.entrySet()) {
|
| - |
|
238 |
|
| - |
|
239 |
for (WebProductListing webProduct : webProductListingEntry.getValue()) {
|
| - |
|
240 |
|
| - |
|
241 |
if (!catalogLabelMap.containsKey(webProduct.getEntityId())) {
|
| - |
|
242 |
|
| - |
|
243 |
catalogLabelMap.put(webProduct.getEntityId(), new ArrayList<>());
|
| - |
|
244 |
|
| - |
|
245 |
}
|
| - |
|
246 |
|
| - |
|
247 |
List<String> itemLabels = catalogLabelMap.get(webProduct.getEntityId());
|
| - |
|
248 |
itemLabels.add(webListing.get(webProduct.getWebListingId()));
|
| - |
|
249 |
catalogLabelMap.put(webProduct.getEntityId(), itemLabels);
|
| - |
|
250 |
|
| - |
|
251 |
}
|
| - |
|
252 |
|
| - |
|
253 |
}
|
| - |
|
254 |
|
| - |
|
255 |
return catalogLabelMap;
|
| - |
|
256 |
}
|
| - |
|
257 |
|
| 217 |
public void populateTagItems() throws Exception {
|
258 |
public void populateTagItems() throws Exception {
|
| 218 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
|
259 |
Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
|
| 219 |
List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
|
260 |
List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
|
| 220 |
List<Integer> rankingList = new ArrayList<>();
|
261 |
List<Integer> rankingList = new ArrayList<>();
|
| 221 |
Map<Integer, String> featureMap = new HashMap<>();
|
262 |
Map<Integer, String> featureMap = new HashMap<>();
|
| Line 223... |
Line 264... |
| 223 |
rankingList.add(tagRanking.getCatalogItemId());
|
264 |
rankingList.add(tagRanking.getCatalogItemId());
|
| 224 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
265 |
featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
|
| 225 |
}
|
266 |
}
|
| 226 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
267 |
Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
|
| 227 |
|
268 |
|
| 228 |
List<status> statuses = new ArrayList<>();
|
269 |
List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
|
| - |
|
270 |
|
| 229 |
statuses.add(status.ACTIVE);
|
271 |
Map<Integer, List<String>> catalogLabelMap = this.getLabels();
|
| - |
|
272 |
|
| 230 |
statuses.add(status.PAUSED_BY_RISK);
|
273 |
logger.info("catalogLabelMap {}", catalogLabelMap);
|
| - |
|
274 |
|
| - |
|
275 |
/*
|
| 231 |
statuses.add(status.PARTIALLY_ACTIVE);
|
276 |
* List<ItemTagModel> tuples =
|
| 232 |
/* List<ItemTagModel> tuples = tagListingRepository.getAllItemTagByStatus(statuses).stream()
|
277 |
* tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
|
| 233 |
.filter(x -> x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());*/
|
278 |
* x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
|
| 234 |
|
279 |
*/
|
| - |
|
280 |
|
| 235 |
List<ItemTagModel> tuples = tagListingRepository.getAllItemTagByStatus(statuses);
|
281 |
List<ItemTagModel> tuples = tagListingRepository.getAllItemTagByStatus(statuses);
|
| 236 |
|
282 |
|
| 237 |
Map<String, Object> projection = new HashMap<>();
|
283 |
Map<String, Object> projection = new HashMap<>();
|
| 238 |
projection.put("defaultImageUrl", 1);
|
284 |
projection.put("defaultImageUrl", 1);
|
| 239 |
|
285 |
|
| 240 |
List<String> excludeBrands = Arrays.asList("Live Demo", "FOC", "Dummy", "FOC HANDSET");
|
286 |
List<String> excludeBrands = Arrays.asList("Live Demo", "Dummy", "FOC HANDSET");
|
| 241 |
|
287 |
|
| 242 |
for (ItemTagModel result : tuples) {
|
288 |
for (ItemTagModel result : tuples) {
|
| 243 |
TagListing tag = result.getTagListing();
|
289 |
TagListing tag = result.getTagListing();
|
| 244 |
com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem();
|
290 |
com.spice.profitmandi.dao.entity.catalog.Item item = result.getItem();
|
| 245 |
if (excludeBrands.contains(item.getBrand())) {
|
291 |
if (excludeBrands.contains(item.getBrand())) {
|
| Line 250... |
Line 296... |
| 250 |
Map<String, Object> catalogObj = new HashMap<>();
|
296 |
Map<String, Object> catalogObj = new HashMap<>();
|
| 251 |
catalogObj.put("feature", "");
|
297 |
catalogObj.put("feature", "");
|
| 252 |
catalogObj.put("title",
|
298 |
catalogObj.put("title",
|
| 253 |
String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
|
299 |
String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
|
| 254 |
.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
|
300 |
.stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
|
| 255 |
catalogObj.put("brand", item.getBrand());
|
301 |
catalogObj.put("brand", new String[] { item.getBrand() });
|
| 256 |
if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
|
302 |
if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
|
| 257 |
catalogObj.put("brand", new String[] { "Huawei", "Honor" });
|
303 |
catalogObj.put("brand", new String[] { "Huawei", "Honor" });
|
| 258 |
}
|
304 |
}
|
| 259 |
if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
|
305 |
if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
|
| 260 |
|| item.getBrand().equals("Redmi")) {
|
306 |
|| item.getBrand().equals("Redmi")) {
|
| Line 296... |
Line 342... |
| 296 |
|
342 |
|
| 297 |
if (item.getCategoryId() == 10006) {
|
343 |
if (item.getCategoryId() == 10006) {
|
| 298 |
catalogObj.put("categoryId", 3);
|
344 |
catalogObj.put("categoryId", 3);
|
| 299 |
}
|
345 |
}
|
| 300 |
catalogObj.put("subCategoryId", item.getCategoryId());
|
346 |
catalogObj.put("subCategoryId", item.getCategoryId());
|
| - |
|
347 |
catalogObj.put("create_timestamp",
|
| 301 |
catalogObj.put("create_timestamp", tag.getCreatedTimestamp().atZone(ZoneId.systemDefault())
|
348 |
tag.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
|
| - |
|
349 |
|
| 302 |
.toInstant().toEpochMilli());
|
350 |
if (catalogLabelMap.containsKey(item.getCatalogItemId())
|
| - |
|
351 |
&& catalogLabelMap.get(item.getCatalogItemId()) != null) {
|
| - |
|
352 |
catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
|
| - |
|
353 |
|
| - |
|
354 |
}
|
| 303 |
catalogMap.put(item.getCatalogItemId(), catalogObj);
|
355 |
catalogMap.put(item.getCatalogItemId(), catalogObj);
|
| 304 |
catalogObj.put("avColor", new HashMap<>());
|
356 |
catalogObj.put("avColor", new HashMap<>());
|
| - |
|
357 |
|
| 305 |
}
|
358 |
}
|
| 306 |
|
359 |
|
| 307 |
Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
|
360 |
Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
|
| 308 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
|
361 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
|
| 309 |
|
362 |
|
| Line 391... |
Line 444... |
| 391 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
444 |
SolrInputDocument catalogSolrObj = new SolrInputDocument();
|
| 392 |
|
445 |
|
| 393 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
446 |
catalogSolrObj.setField("id", "catalog" + catalogId);
|
| 394 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
447 |
catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
|
| 395 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
448 |
catalogSolrObj.setField("title_s", catalogValMap.get("title"));
|
| 396 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
449 |
// catalogSolrObj.setField("_childDocuments_", itemObjs);
|
| 397 |
catalogSolrObj.addChildDocuments(itemObjs);
|
450 |
catalogSolrObj.addChildDocuments(itemObjs);
|
| 398 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
451 |
catalogSolrObj.setField("child_b", itemObjs.size() > 0);
|
| 399 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
452 |
catalogSolrObj.setField("catalogId_i", catalogId);
|
| 400 |
catalogSolrObj.setField("imageUrl_s",
|
453 |
catalogSolrObj.setField("imageUrl_s",
|
| 401 |
catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
|
454 |
catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
|
| 402 |
catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
|
455 |
catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
|
| 403 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
456 |
catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
|
| 404 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
457 |
catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
|
| 405 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
458 |
catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
|
| 406 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
459 |
catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
|
| - |
|
460 |
catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
|
| 407 |
catalogSolrObj.setField("w7573_i", 0);
|
461 |
catalogSolrObj.setField("w7573_i", 0);
|
| 408 |
catalogSolrObj.setField("w7678_i", 0);
|
462 |
catalogSolrObj.setField("w7678_i", 0);
|
| 409 |
catalogSolrObj.setField("w7720_i", 0);
|
463 |
catalogSolrObj.setField("w7720_i", 0);
|
| 410 |
catalogSolrObj.setField("w8468_i", 0);
|
464 |
catalogSolrObj.setField("w8468_i", 0);
|
| 411 |
catalogSolrObj.setField("w8889_i", 0);
|
465 |
catalogSolrObj.setField("w8889_i", 0);
|
| 412 |
catalogSolrObj.setField("w8947_i", 0);
|
466 |
catalogSolrObj.setField("w8947_i", 0);
|
| 413 |
catalogSolrObj.setField("w9213_i", 0);
|
467 |
catalogSolrObj.setField("w9213_i", 0);
|
| 414 |
catalogSolrObj.setField("w9203_i", 0);
|
468 |
catalogSolrObj.setField("w9203_i", 0);
|
| 415 |
catalogSolrObj.setField("mop_f", mop);
|
469 |
catalogSolrObj.setField("mop_f", mop);
|
| - |
|
470 |
catalogSolrObj.setField("show_default_b", false);
|
| - |
|
471 |
|
| - |
|
472 |
String[] brands = (String[]) catalogValMap.get("brand");
|
| - |
|
473 |
for (String brand : brands) {
|
| - |
|
474 |
if (brand != "FOC") {
|
| - |
|
475 |
catalogSolrObj.setField("show_default_b", true);
|
| - |
|
476 |
|
| - |
|
477 |
}
|
| - |
|
478 |
}
|
| 416 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
479 |
Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
|
| 417 |
|
480 |
|
| 418 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
481 |
for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
|
| 419 |
int whId = avColorEntry.getKey();
|
482 |
int whId = avColorEntry.getKey();
|
| 420 |
int color = (int) avColorEntry.getValue();
|
483 |
int color = (int) avColorEntry.getValue();
|
| Line 429... |
Line 492... |
| 429 |
|
492 |
|
| 430 |
logger.info("catalogSolrObjs {}", catalogSolrObjs);
|
493 |
logger.info("catalogSolrObjs {}", catalogSolrObjs);
|
| 431 |
solr.deleteByQuery("*:*");
|
494 |
solr.deleteByQuery("*:*");
|
| 432 |
solr.add(catalogSolrObjs);
|
495 |
solr.add(catalogSolrObjs);
|
| 433 |
|
496 |
|
| 434 |
UpdateResponse updateResponse = solr.commit();
|
497 |
org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
|
| 435 |
logger.info("solr {}", updateResponse.getStatus());
|
498 |
logger.info("solr {}", updateResponse.getStatus());
|
| 436 |
|
499 |
|
| 437 |
}
|
500 |
}
|
| 438 |
|
501 |
|
| 439 |
/*
|
502 |
/*
|