@infrab4a/connect-angular 4.1.3 → 4.1.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/services/catalog/catalog.service.mjs +38 -2
- package/fesm2015/infrab4a-connect-angular.mjs +36 -0
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +36 -0
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +1 -1
- package/services/catalog/catalog.service.d.ts +3 -0
|
@@ -1436,6 +1436,7 @@ class CatalogService {
|
|
|
1436
1436
|
this.categoryStructureAdapter = categoryStructureAdapter;
|
|
1437
1437
|
this.shop = shop;
|
|
1438
1438
|
this.productIndex = productIndex;
|
|
1439
|
+
this.productsByTerm = {};
|
|
1439
1440
|
this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, tags, rate, customOptions, }) => {
|
|
1440
1441
|
const filters = {};
|
|
1441
1442
|
if (clubDiscount?.length)
|
|
@@ -1506,6 +1507,8 @@ class CatalogService {
|
|
|
1506
1507
|
}));
|
|
1507
1508
|
}
|
|
1508
1509
|
async findCatalog(options, limits) {
|
|
1510
|
+
if (this.hasTerm(options) && options.sort === 'most-relevant')
|
|
1511
|
+
return this.findCatalogByTermAndSortByMostRevelant(options, limits);
|
|
1509
1512
|
const repoParams = {
|
|
1510
1513
|
filters: {
|
|
1511
1514
|
...(await this.buildMainFilter(options)),
|
|
@@ -1533,6 +1536,39 @@ class CatalogService {
|
|
|
1533
1536
|
.search(term, 999, this.shop)
|
|
1534
1537
|
.then((data) => ({ id: { operator: Where.IN, value: data.hits.map(({ _source }) => _source.id) } }));
|
|
1535
1538
|
}
|
|
1539
|
+
async findCatalogByTermAndSortByMostRevelant(options, limits) {
|
|
1540
|
+
const productIds = await this.findCatalogIdsByElasticSearch(options.term);
|
|
1541
|
+
const limitedProductId = productIds.slice(limits.offset, limits.limit);
|
|
1542
|
+
const productResult = await this.productRepository.findCatalog({
|
|
1543
|
+
filters: { id: { operator: Where.IN, value: limitedProductId } },
|
|
1544
|
+
options: {
|
|
1545
|
+
minimal: ['price'],
|
|
1546
|
+
maximum: ['price'],
|
|
1547
|
+
...(!this.hasCategory(options) ? { distinct: ['brand'] } : {}),
|
|
1548
|
+
},
|
|
1549
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1550
|
+
const totalResult = await this.productRepository.findCatalog({
|
|
1551
|
+
fields: ['id'],
|
|
1552
|
+
filters: { id: { operator: Where.IN, value: productIds } },
|
|
1553
|
+
limits: { limit: 1, offset: 0 },
|
|
1554
|
+
options: {
|
|
1555
|
+
minimal: ['price'],
|
|
1556
|
+
maximum: ['price'],
|
|
1557
|
+
distinct: ['brand'],
|
|
1558
|
+
},
|
|
1559
|
+
}, options?.mainGender || this.shop === Shops.MENSMARKET ? 'male' : 'female');
|
|
1560
|
+
return {
|
|
1561
|
+
data: limitedProductId.map((id) => productResult.data.find((product) => product.id === id)),
|
|
1562
|
+
count: totalResult.count,
|
|
1563
|
+
maximum: totalResult.maximum,
|
|
1564
|
+
minimal: totalResult.minimal,
|
|
1565
|
+
distinct: totalResult.distinct,
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
async findCatalogIdsByElasticSearch(term) {
|
|
1569
|
+
return (this.productsByTerm[term] ||
|
|
1570
|
+
this.productIndex.search(term, 999, this.shop).then((data) => data.hits.map(({ _source }) => _source.id)));
|
|
1571
|
+
}
|
|
1536
1572
|
}
|
|
1537
1573
|
CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: CATEGORY_STRUCTURE }, { token: DEFAULT_SHOP }, { token: i1$2.ProductsIndex }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1538
1574
|
CatalogService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService });
|