diff --git a/packages/algoliasearch-helper/index.d.ts b/packages/algoliasearch-helper/index.d.ts index 3dc6603c51..e3ea213ba4 100644 --- a/packages/algoliasearch-helper/index.d.ts +++ b/packages/algoliasearch-helper/index.d.ts @@ -1114,7 +1114,6 @@ declare namespace algoliasearchHelper { * This is for internal use, e.g., avoiding caching in infinite hits, or delaying the display of these results. */ __isArtificial?: boolean | undefined; - persistHierarchicalRootCount?: boolean; } type ISearchResponse = Omit, 'facets' | 'params'> & diff --git a/packages/algoliasearch-helper/src/SearchResults/index.js b/packages/algoliasearch-helper/src/SearchResults/index.js index 36af0dba1b..e501c490db 100644 --- a/packages/algoliasearch-helper/src/SearchResults/index.js +++ b/packages/algoliasearch-helper/src/SearchResults/index.js @@ -240,11 +240,8 @@ function SearchResults(state, results, options) { }); // Make every key of the result options reachable from the instance - var opts = defaultsPure(options, { - persistHierarchicalRootCount: true, - }); - Object.keys(opts).forEach(function (key) { - self[key] = opts[key]; + Object.keys(options || {}).forEach(function (key) { + self[key] = options[key]; }); /** @@ -508,16 +505,10 @@ function SearchResults(state, results, options) { return; } - self.hierarchicalFacets[position][attributeIndex].data = - self.persistHierarchicalRootCount - ? defaultsPure( - self.hierarchicalFacets[position][attributeIndex].data, - facetResults - ) - : defaultsPure( - facetResults, - self.hierarchicalFacets[position][attributeIndex].data - ); + self.hierarchicalFacets[position][attributeIndex].data = defaultsPure( + self.hierarchicalFacets[position][attributeIndex].data, + facetResults + ); } else { position = disjunctiveFacetsIndices[dfacet]; @@ -589,28 +580,7 @@ function SearchResults(state, results, options) { return; } - // when we always get root levels, if the hits refinement is `beers > IPA` (count: 5), - // then the disjunctive values will be `beers` (count: 100), - // but we do not want to display - // | beers (100) - // > IPA (5) - // We want - // | beers (5) - // > IPA (5) - // @MAJOR: remove this legacy behaviour in next major version - var defaultData = {}; - - if ( - currentRefinement.length > 0 && - !self.persistHierarchicalRootCount - ) { - var root = currentRefinement[0].split(separator)[0]; - defaultData[root] = - self.hierarchicalFacets[position][attributeIndex].data[root]; - } - self.hierarchicalFacets[position][attributeIndex].data = defaultsPure( - defaultData, facetResults, self.hierarchicalFacets[position][attributeIndex].data ); diff --git a/packages/algoliasearch-helper/test/datasets/SearchParameters/search.dataset.js b/packages/algoliasearch-helper/test/datasets/SearchParameters/search.dataset.js index 639de95f25..4ff8f7c50b 100644 --- a/packages/algoliasearch-helper/test/datasets/SearchParameters/search.dataset.js +++ b/packages/algoliasearch-helper/test/datasets/SearchParameters/search.dataset.js @@ -336,7 +336,6 @@ function getData() { index: 'test_hotels-node', hitsPerPage: 20, nbHits: 4, - persistHierarchicalRootCount: true, nbPages: 1, page: 0, params: diff --git a/packages/algoliasearch-helper/test/spec/SearchResults/getFacetValues.js b/packages/algoliasearch-helper/test/spec/SearchResults/getFacetValues.js index 53b38e39f0..33b6f80b68 100644 --- a/packages/algoliasearch-helper/test/spec/SearchResults/getFacetValues.js +++ b/packages/algoliasearch-helper/test/spec/SearchResults/getFacetValues.js @@ -751,12 +751,10 @@ test('getFacetValues(facetName) prefers the "main" facet result (disjunctive)', expect(facetValues).toEqual(expected); }); -test('getFacetValues(facetName) prefers the "main" facet result (hierarchical) (persistHierarchicalRootCount: true)', function () { +test('getFacetValues(facetName) prefers the "main" facet result (hierarchical)', function () { var data = require('./getFacetValues/hierarchical-non-exhaustive.json'); var searchParams = new SearchParameters(data.state); - var result = new SearchResults(searchParams, data.content.results, { - persistHierarchicalRootCount: true, - }); + var result = new SearchResults(searchParams, data.content.results); var facetValues = result.getFacetValues('brand').data; @@ -792,45 +790,3 @@ test('getFacetValues(facetName) prefers the "main" facet result (hierarchical) ( expect(facetValues).toEqual(expected); }); - -test('getFacetValues(facetName) prefers the "main" facet result (hierarchical) (persistHierarchicalRootCount: false)', function () { - var data = require('./getFacetValues/hierarchical-non-exhaustive.json'); - var searchParams = new SearchParameters(data.state); - var result = new SearchResults(searchParams, data.content.results, { - persistHierarchicalRootCount: false, - }); - - var facetValues = result.getFacetValues('brand').data; - - var expected = [ - { - count: 50, - data: null, - isRefined: true, - name: 'Apple', - escapedValue: 'Apple', - path: 'Apple', - exhaustive: true, - }, - { - count: 551, - data: null, - isRefined: false, - name: 'Insignia™', - escapedValue: 'Insignia™', - path: 'Insignia™', - exhaustive: true, - }, - { - count: 551, - data: null, - isRefined: false, - name: 'Samsung', - escapedValue: 'Samsung', - path: 'Samsung', - exhaustive: true, - }, - ]; - - expect(facetValues).toEqual(expected); -}); diff --git a/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js b/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js index 1011e8d675..f3b60af493 100644 --- a/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js +++ b/packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js @@ -86,196 +86,20 @@ describe('hierarchical facets: simple usage', function () { client.search.mockClear(); }); - test('persistHierarchicalRootCount: false', function (done) { - var helper = algoliasearchHelper( - client, - indexName, - { - hierarchicalFacets: [ - { - name: 'categories', - attributes: [ - 'categories.lvl0', - 'categories.lvl1', - 'categories.lvl2', - 'categories.lvl3', - ], - }, - ], - }, - { - persistHierarchicalRootCount: false, - } - ); - - helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); - - var expectedHelperResponse = [ - { - name: 'categories', - count: null, - isRefined: true, - path: null, - escapedValue: null, - exhaustive: true, - data: [ - { - name: 'beers', - path: 'beers', - escapedValue: 'beers', - count: 9, - isRefined: true, - exhaustive: true, - data: [ - { - name: 'IPA', - path: 'beers > IPA', - escapedValue: 'beers > IPA', - count: 9, - isRefined: true, - exhaustive: true, - data: [ - { - name: 'Flying dog', - path: 'beers > IPA > Flying dog', - escapedValue: 'beers > IPA > Flying dog', - count: 3, - isRefined: true, - exhaustive: true, - data: null, - }, - { - name: 'Brewdog punk IPA', - path: 'beers > IPA > Brewdog punk IPA', - escapedValue: 'beers > IPA > Brewdog punk IPA', - count: 6, - isRefined: false, - exhaustive: true, - data: null, - }, - ], - }, - { - name: 'Pale Ale', - path: 'beers > Pale Ale', - escapedValue: 'beers > Pale Ale', - count: 10, - isRefined: false, - exhaustive: true, - data: null, - }, - { - name: 'Stout', - path: 'beers > Stout', - escapedValue: 'beers > Stout', - count: 1, - isRefined: false, - exhaustive: true, - data: null, - }, - ], - }, - { - name: 'fruits', - path: 'fruits', - escapedValue: 'fruits', - count: 5, - isRefined: false, - exhaustive: true, - data: null, - }, - { - name: 'sales', - path: 'sales', - escapedValue: 'sales', - count: 20, - isRefined: false, - exhaustive: true, - data: null, - }, - ], - }, - ]; - - helper.setQuery('a').search(); - - helper.once('result', function (event) { - var queries = client.search.mock.calls[0][0]; - var hitsQuery = queries[0]; - var parentValuesQuery = queries[1]; - var fullParentsValuesQueries = queries.slice(2); - - expect(queries.length).toBe(4); - - expect(hitsQuery.params.facets).toEqual([ - 'categories.lvl0', - 'categories.lvl1', - 'categories.lvl2', - 'categories.lvl3', - ]); - expect(hitsQuery.params.facetFilters).toEqual([ - ['categories.lvl2:beers > IPA > Flying dog'], - ]); - - expect(parentValuesQuery.params.facets).toEqual([ - 'categories.lvl0', - 'categories.lvl1', - 'categories.lvl2', - ]); - expect(parentValuesQuery.params.facetFilters).toEqual([ - ['categories.lvl1:beers > IPA'], - ]); - - // Root - expect(fullParentsValuesQueries[0].params.facets).toEqual( - 'categories.lvl0' - ); - expect(fullParentsValuesQueries[0].params.facetFilters).toBe(undefined); - - // Level 1 - expect(fullParentsValuesQueries[1].params.facets).toEqual( - 'categories.lvl1' - ); - expect(fullParentsValuesQueries[1].params.facetFilters).toEqual([ - 'categories.lvl0:beers', - ]); - - expect(event.results.hierarchicalFacets).toEqual(expectedHelperResponse); - expect( - event.results.hierarchicalFacets.find((f) => f.name === 'categories') - ).toEqual(expectedHelperResponse[0]); - - // we do not yet support multiple values for hierarchicalFacetsRefinements - // but at some point we may want to open multiple leafs of a hierarchical menu - // So we set this as an array so that we do not have to bump major to handle it - expect( - Array.isArray(helper.state.hierarchicalFacetsRefinements.categories) - ).toBeTruthy(); - done(); + test('simple usage', function (done) { + var helper = algoliasearchHelper(client, indexName, { + hierarchicalFacets: [ + { + name: 'categories', + attributes: [ + 'categories.lvl0', + 'categories.lvl1', + 'categories.lvl2', + 'categories.lvl3', + ], + }, + ], }); - }); - - test('persistHierarchicalRootCount: true', function (done) { - var helper = algoliasearchHelper( - client, - indexName, - { - hierarchicalFacets: [ - { - name: 'categories', - attributes: [ - 'categories.lvl0', - 'categories.lvl1', - 'categories.lvl2', - 'categories.lvl3', - ], - }, - ], - }, - { - persistHierarchicalRootCount: true, - } - ); helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog'); diff --git a/packages/instantsearch-core/src/__tests__/instantsearch.test.tsx b/packages/instantsearch-core/src/__tests__/instantsearch.test.tsx index 0c42821409..89786f6b9a 100644 --- a/packages/instantsearch-core/src/__tests__/instantsearch.test.tsx +++ b/packages/instantsearch-core/src/__tests__/instantsearch.test.tsx @@ -864,30 +864,7 @@ describe('start', () => { expect(algoliasearchHelper).toHaveBeenCalledWith( searchClient, indexName, - undefined, - { persistHierarchicalRootCount: true } - ); - }); - - it('creates a Helper with `persistHierarchicalRootCount` set to true when specified with a future flag', () => { - const searchClient = createSearchClient(); - const indexName = 'indexName'; - const future = { - persistHierarchicalRootCount: true, - }; - const search = new InstantSearch({ - indexName, - searchClient, - future, - }); - - search.start(); - - expect(algoliasearchHelper).toHaveBeenCalledWith( - searchClient, - indexName, - undefined, - { persistHierarchicalRootCount: true } + undefined ); }); diff --git a/packages/instantsearch-core/src/instantsearch.ts b/packages/instantsearch-core/src/instantsearch.ts index a48e8e0a0c..05074efd4e 100644 --- a/packages/instantsearch-core/src/instantsearch.ts +++ b/packages/instantsearch-core/src/instantsearch.ts @@ -52,7 +52,6 @@ export const INSTANTSEARCH_FUTURE_DEFAULTS: Required< InstantSearchOptions['future'] > = { preserveSharedStateOnUnmount: false, - persistHierarchicalRootCount: true, }; /** @@ -343,9 +342,7 @@ See documentation: ${createDocumentationLink({ // we need to respect this helper as a way to keep all listeners correct. const mainHelper = this.mainHelper || - algoliasearchHelper(this.client, this.indexName, undefined, { - persistHierarchicalRootCount: this.future.persistHierarchicalRootCount, - }); + algoliasearchHelper(this.client, this.indexName, undefined); mainHelper.search = () => { this.status = 'loading'; diff --git a/packages/instantsearch-core/src/types/instantsearch.ts b/packages/instantsearch-core/src/types/instantsearch.ts index c858654f6b..c03d426a94 100644 --- a/packages/instantsearch-core/src/types/instantsearch.ts +++ b/packages/instantsearch-core/src/types/instantsearch.ts @@ -101,16 +101,6 @@ export type InstantSearchOptions< * @default false */ preserveSharedStateOnUnmount?: boolean; // @MAJOR remove option, only keep the "true" behaviour - /** - * Changes the way root levels of hierarchical facets have their count displayed. - * - * If `false` (by default), the count of the refined root level is updated to match the count of the actively refined parent level. - * - * If `true`, the count of the root level stays the same as the count of all children levels. - * - * @default true - */ - persistHierarchicalRootCount?: boolean; // @MAJOR remove the option }; }; diff --git a/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts b/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts index 7b01396d80..4884a84f38 100644 --- a/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts +++ b/packages/instantsearch-core/src/widgets/__tests__/index-widget.test.ts @@ -3346,7 +3346,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index-widge nbPages: 1, page: 0, params: '', - persistHierarchicalRootCount: true, processingTimeMS: 0, query: 'iphone', };