elasticsearch-plugin-test
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -86,3 +86,2 @@ "use strict"; | ||
if (sort.price) { | ||
// const priceField = groupByProduct ? 'priceMin' : 'price'; | ||
const priceField = 'price'; | ||
@@ -92,25 +91,15 @@ sortArray.push({ [priceField]: { order: sort.price === generated_types_1.SortOrder.ASC ? 'asc' : 'desc' } }); | ||
} | ||
const body = { | ||
query: searchConfig.mapQuery | ||
? searchConfig.mapQuery(query, input, searchConfig, channelId, enabledOnly) | ||
: query, | ||
sort: sortArray, | ||
from: skip || 0, | ||
size: take || 10, | ||
track_total_hits: searchConfig.totalItemsMaxSize, | ||
}; | ||
if (groupByProduct) { | ||
return { | ||
query: searchConfig.mapQuery | ||
? searchConfig.mapQuery(query, input, searchConfig, channelId, enabledOnly) | ||
: query, | ||
sort: sortArray, | ||
from: skip || 0, | ||
size: take || 10, | ||
track_total_hits: searchConfig.totalItemsMaxSize, | ||
collapse: { field: `productId` }, | ||
}; | ||
body.collapse = { field: `productId` }; | ||
} | ||
else { | ||
return { | ||
query: searchConfig.mapQuery | ||
? searchConfig.mapQuery(query, input, searchConfig, channelId, enabledOnly) | ||
: query, | ||
sort: sortArray, | ||
from: skip || 0, | ||
size: take || 10, | ||
track_total_hits: searchConfig.totalItemsMaxSize, | ||
}; | ||
} | ||
return body; | ||
} | ||
@@ -117,0 +106,0 @@ exports.buildElasticBody = buildElasticBody; |
@@ -52,4 +52,4 @@ import { OnModuleDestroy, OnModuleInit } from '@nestjs/common'; | ||
private mapProductToSearchResult; | ||
private static getSearchResultAssets; | ||
private getSearchResultAssets; | ||
private static addCustomMappings; | ||
} |
@@ -238,29 +238,19 @@ "use strict"; | ||
elasticSearchBody.size = 0; | ||
elasticSearchBody.aggs = { | ||
collection: { | ||
terms: { | ||
field, | ||
size: this.options.searchConfig.collectionMaxSize, | ||
}, | ||
}, | ||
}; | ||
if (groupByProduct) { | ||
elasticSearchBody.aggs = { | ||
collection: { | ||
terms: { | ||
field, | ||
size: this.options.searchConfig.collectionMaxSize, | ||
elasticSearchBody.aggs.collection.aggs = { | ||
total: { | ||
cardinality: { | ||
field: `productId`, | ||
}, | ||
aggs: { | ||
total: { | ||
cardinality: { | ||
field: `productId`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
else { | ||
elasticSearchBody.aggs = { | ||
collection: { | ||
terms: { | ||
field, | ||
size: this.options.searchConfig.collectionMaxSize, | ||
}, | ||
}, | ||
}; | ||
} | ||
let body; | ||
@@ -354,3 +344,3 @@ try { | ||
const source = hit._source; | ||
const { productAsset, productVariantAsset } = ElasticsearchService_1.getSearchResultAssets(source); | ||
const { productAsset, productVariantAsset } = this.getSearchResultAssets(source); | ||
const result = Object.assign(Object.assign({}, source), { productAsset, | ||
@@ -367,5 +357,5 @@ productVariantAsset, price: { | ||
const source = hit._source; | ||
const { productAsset, productVariantAsset } = ElasticsearchService_1.getSearchResultAssets(source); | ||
const { productAsset, productVariantAsset } = this.getSearchResultAssets(source); | ||
const result = Object.assign(Object.assign({}, source), { productAsset, | ||
productVariantAsset, productId: source.productId.toString(), productName: source.productName, productVariantId: source.productVariantId.toString(), productVariantName: source.productVariantName, facetIds: source.productFacetIds, facetValueIds: source.productFacetValueIds, collectionIds: source.productCollectionIds, sku: source.sku, slug: source.slug, price: { | ||
productVariantAsset, enabled: source.productEnabled, productId: source.productId.toString(), productName: source.productName, productVariantId: source.productVariantId.toString(), productVariantName: source.productVariantName, facetIds: source.productFacetIds, facetValueIds: source.productFacetValueIds, collectionIds: source.productCollectionIds, sku: source.sku, slug: source.slug, price: { | ||
min: source.productPriceMin, | ||
@@ -380,3 +370,3 @@ max: source.productPriceMax, | ||
} | ||
static getSearchResultAssets(source) { | ||
getSearchResultAssets(source) { | ||
const productAsset = source.productAssetId | ||
@@ -383,0 +373,0 @@ ? { |
@@ -352,3 +352,7 @@ "use strict"; | ||
core_1.Logger.verbose(`Updating Product (${productId})`, constants_1.loggerCtx); | ||
const languageVariants = product.translations.map(t => t.languageCode); | ||
const languageVariants = []; | ||
languageVariants.push(...product.translations.map(t => t.languageCode)); | ||
for (const variant of product.variants) { | ||
languageVariants.push(...variant.translations.map(t => t.languageCode)); | ||
} | ||
for (const channel of product.channels) { | ||
@@ -421,5 +425,9 @@ const channelCtx = new core_1.RequestContext({ | ||
const operations = []; | ||
const languageVariants = []; | ||
languageVariants.push(...product.translations.map(t => t.languageCode)); | ||
for (const variant of product.variants) { | ||
languageVariants.push(...variant.translations.map(t => t.languageCode)); | ||
} | ||
for (const { id: channelId } of channels) { | ||
const languageVariants = product.translations.map(t => t.languageCode); | ||
for (const languageCode of languageVariants) { | ||
for (const languageCode of unique_1.unique(languageVariants)) { | ||
operations.push({ | ||
@@ -435,6 +443,6 @@ index: constants_1.VARIANT_INDEX_NAME, | ||
} | ||
operations.push(...(await this.deleteVariantsInternalOperations(product.variants, channels.map(c => c.id)))); | ||
operations.push(...(await this.deleteVariantsInternalOperations(product.variants, channels.map(c => c.id), languageVariants))); | ||
return operations; | ||
} | ||
async deleteVariantsInternalOperations(variants, channelIds) { | ||
async deleteVariantsInternalOperations(variants, channelIds, languageVariants) { | ||
core_1.Logger.verbose(`Deleting ${variants.length} ProductVariants`, constants_1.loggerCtx); | ||
@@ -444,3 +452,2 @@ const operations = []; | ||
for (const channelId of channelIds) { | ||
const languageVariants = variant.translations.map(t => t.languageCode); | ||
for (const languageCode of languageVariants) { | ||
@@ -547,2 +554,3 @@ operations.push({ | ||
enabled: v.enabled && v.product.enabled, | ||
productEnabled: variants.some(variant => variant.enabled) && v.product.enabled, | ||
productPriceMin: Math.min(...prices), | ||
@@ -601,2 +609,3 @@ productPriceMax: Math.max(...prices), | ||
enabled: false, | ||
productEnabled: false, | ||
productPriceMin: 0, | ||
@@ -603,0 +612,0 @@ productPriceMax: 0, |
@@ -17,3 +17,3 @@ "use strict"; | ||
const keyword = { type: 'keyword' }; | ||
const variantMappings = Object.assign({ sku: textWithKeyword, slug: textWithKeyword, productId: keyword, channelId: keyword, languageCode: keyword, productName: textWithKeyword, productVariantId: keyword, productVariantName: textWithKeyword, currencyCode: keyword, description: textWithKeyword, facetIds: keyword, facetValueIds: keyword, collectionIds: keyword, collectionSlugs: keyword, channelIds: keyword, enabled: { type: 'boolean' }, productAssetId: keyword, productPreview: textWithKeyword, productPreviewFocalPoint: { type: 'object' }, productVariantAssetId: keyword, productVariantPreview: textWithKeyword, productVariantPreviewFocalPoint: { type: 'object' }, productChannelIds: keyword, productCollectionIds: keyword, productCollectionSlugs: keyword, productFacetIds: keyword, productFacetValueIds: keyword, productPriceMax: { type: 'long' }, productPriceMin: { type: 'long' }, productPriceWithTaxMax: { type: 'long' }, productPriceWithTaxMin: { type: 'long' }, price: { type: 'long' }, priceWithTax: { type: 'long' } }, indexMappingProperties); | ||
const variantMappings = Object.assign({ sku: textWithKeyword, slug: textWithKeyword, productId: keyword, channelId: keyword, languageCode: keyword, productName: textWithKeyword, productVariantId: keyword, productVariantName: textWithKeyword, currencyCode: keyword, description: textWithKeyword, facetIds: keyword, facetValueIds: keyword, collectionIds: keyword, collectionSlugs: keyword, channelIds: keyword, enabled: { type: 'boolean' }, productEnabled: { type: 'boolean' }, productAssetId: keyword, productPreview: textWithKeyword, productPreviewFocalPoint: { type: 'object' }, productVariantAssetId: keyword, productVariantPreview: textWithKeyword, productVariantPreviewFocalPoint: { type: 'object' }, productChannelIds: keyword, productCollectionIds: keyword, productCollectionSlugs: keyword, productFacetIds: keyword, productFacetValueIds: keyword, productPriceMax: { type: 'long' }, productPriceMin: { type: 'long' }, productPriceWithTaxMax: { type: 'long' }, productPriceWithTaxMin: { type: 'long' }, price: { type: 'long' }, priceWithTax: { type: 'long' } }, indexMappingProperties); | ||
const unixtimestampPostfix = new Date().getTime(); | ||
@@ -20,0 +20,0 @@ const createIndex = async (mappings, index, alias) => { |
@@ -35,2 +35,3 @@ import { Coordinate, CurrencyCode, LanguageCode, PriceRange, SearchInput, SearchResponse, SearchResult } from '@vendure/common/lib/generated-types'; | ||
collectionSlugs: string[]; | ||
productEnabled: boolean; | ||
productPriceMin: number; | ||
@@ -64,2 +65,3 @@ productPriceMax: number; | ||
enabled: boolean; | ||
productEnabled: boolean; | ||
priceMin: number; | ||
@@ -66,0 +68,0 @@ priceMax: number; |
{ | ||
"name": "elasticsearch-plugin-test", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
196406
3145