Explorar el Código

fix(core): Fix ONLY_FULL_GROUP_BY error when searching with MySQL

Fixes #1236
Michael Bromley hace 4 años
padre
commit
94fa4db194

+ 17 - 0
packages/core/e2e/default-search-plugin.e2e-spec.ts

@@ -524,6 +524,23 @@ describe('Default search plugin', () => {
             ]);
         });
 
+        // https://github.com/vendure-ecommerce/vendure/issues/1236
+        it('returns correct facetValues when not grouped by product, with search term', async () => {
+            const result = await shopClient.query<SearchFacetValues.Query, SearchFacetValues.Variables>(
+                SEARCH_GET_FACET_VALUES,
+                {
+                    input: {
+                        groupByProduct: false,
+                        term: 'laptop',
+                    },
+                },
+            );
+            expect(result.search.facetValues).toEqual([
+                { count: 4, facetValue: { id: 'T_1', name: 'electronics' } },
+                { count: 4, facetValue: { id: 'T_2', name: 'computers' } },
+            ]);
+        });
+
         it('omits facetValues of private facets', async () => {
             const { createFacet } = await adminClient.query<CreateFacet.Mutation, CreateFacet.Variables>(
                 CREATE_FACET,

+ 1 - 1
packages/core/src/plugin/default-search-plugin/search-strategy/mysql-search-strategy.ts

@@ -38,7 +38,7 @@ export class MysqlSearchStrategy implements SearchStrategy {
             .select(['MIN(productId)', 'MIN(productVariantId)'])
             .addSelect('GROUP_CONCAT(facetValueIds)', 'facetValues');
 
-        this.applyTermAndFilters(ctx, facetValuesQb, input);
+        this.applyTermAndFilters(ctx, facetValuesQb, { ...input, groupByProduct: true });
         if (!input.groupByProduct) {
             facetValuesQb.groupBy('productVariantId');
         }