Skip to content

Commit 5721ac8

Browse files
committed
fix(options): remove persistHierarchicalRootCount option
It behaves as persistHierarchicalRootCount: true
1 parent 34cca9a commit 5721ac8

File tree

9 files changed

+23
-312
lines changed

9 files changed

+23
-312
lines changed

packages/algoliasearch-helper/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,6 @@ declare namespace algoliasearchHelper {
11141114
* This is for internal use, e.g., avoiding caching in infinite hits, or delaying the display of these results.
11151115
*/
11161116
__isArtificial?: boolean | undefined;
1117-
persistHierarchicalRootCount?: boolean;
11181117
}
11191118

11201119
type ISearchResponse<T> = Omit<SearchResponse<T>, 'facets' | 'params'> &

packages/algoliasearch-helper/src/SearchResults/index.js

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,8 @@ function SearchResults(state, results, options) {
240240
});
241241

242242
// Make every key of the result options reachable from the instance
243-
var opts = defaultsPure(options, {
244-
persistHierarchicalRootCount: true,
245-
});
246-
Object.keys(opts).forEach(function (key) {
247-
self[key] = opts[key];
243+
Object.keys(options || {}).forEach(function (key) {
244+
self[key] = options[key];
248245
});
249246

250247
/**
@@ -508,16 +505,10 @@ function SearchResults(state, results, options) {
508505
return;
509506
}
510507

511-
self.hierarchicalFacets[position][attributeIndex].data =
512-
self.persistHierarchicalRootCount
513-
? defaultsPure(
514-
self.hierarchicalFacets[position][attributeIndex].data,
515-
facetResults
516-
)
517-
: defaultsPure(
518-
facetResults,
519-
self.hierarchicalFacets[position][attributeIndex].data
520-
);
508+
self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
509+
self.hierarchicalFacets[position][attributeIndex].data,
510+
facetResults
511+
);
521512
} else {
522513
position = disjunctiveFacetsIndices[dfacet];
523514

@@ -589,28 +580,7 @@ function SearchResults(state, results, options) {
589580
return;
590581
}
591582

592-
// when we always get root levels, if the hits refinement is `beers > IPA` (count: 5),
593-
// then the disjunctive values will be `beers` (count: 100),
594-
// but we do not want to display
595-
// | beers (100)
596-
// > IPA (5)
597-
// We want
598-
// | beers (5)
599-
// > IPA (5)
600-
// @MAJOR: remove this legacy behaviour in next major version
601-
var defaultData = {};
602-
603-
if (
604-
currentRefinement.length > 0 &&
605-
!self.persistHierarchicalRootCount
606-
) {
607-
var root = currentRefinement[0].split(separator)[0];
608-
defaultData[root] =
609-
self.hierarchicalFacets[position][attributeIndex].data[root];
610-
}
611-
612583
self.hierarchicalFacets[position][attributeIndex].data = defaultsPure(
613-
defaultData,
614584
facetResults,
615585
self.hierarchicalFacets[position][attributeIndex].data
616586
);

packages/algoliasearch-helper/test/datasets/SearchParameters/search.dataset.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ function getData() {
336336
index: 'test_hotels-node',
337337
hitsPerPage: 20,
338338
nbHits: 4,
339-
persistHierarchicalRootCount: true,
340339
nbPages: 1,
341340
page: 0,
342341
params:

packages/algoliasearch-helper/test/spec/SearchResults/getFacetValues.js

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,10 @@ test('getFacetValues(facetName) prefers the "main" facet result (disjunctive)',
751751
expect(facetValues).toEqual(expected);
752752
});
753753

754-
test('getFacetValues(facetName) prefers the "main" facet result (hierarchical) (persistHierarchicalRootCount: true)', function () {
754+
test('getFacetValues(facetName) prefers the "main" facet result (hierarchical)', function () {
755755
var data = require('./getFacetValues/hierarchical-non-exhaustive.json');
756756
var searchParams = new SearchParameters(data.state);
757-
var result = new SearchResults(searchParams, data.content.results, {
758-
persistHierarchicalRootCount: true,
759-
});
757+
var result = new SearchResults(searchParams, data.content.results);
760758

761759
var facetValues = result.getFacetValues('brand').data;
762760

@@ -792,45 +790,3 @@ test('getFacetValues(facetName) prefers the "main" facet result (hierarchical) (
792790

793791
expect(facetValues).toEqual(expected);
794792
});
795-
796-
test('getFacetValues(facetName) prefers the "main" facet result (hierarchical) (persistHierarchicalRootCount: false)', function () {
797-
var data = require('./getFacetValues/hierarchical-non-exhaustive.json');
798-
var searchParams = new SearchParameters(data.state);
799-
var result = new SearchResults(searchParams, data.content.results, {
800-
persistHierarchicalRootCount: false,
801-
});
802-
803-
var facetValues = result.getFacetValues('brand').data;
804-
805-
var expected = [
806-
{
807-
count: 50,
808-
data: null,
809-
isRefined: true,
810-
name: 'Apple',
811-
escapedValue: 'Apple',
812-
path: 'Apple',
813-
exhaustive: true,
814-
},
815-
{
816-
count: 551,
817-
data: null,
818-
isRefined: false,
819-
name: 'Insignia™',
820-
escapedValue: 'Insignia™',
821-
path: 'Insignia™',
822-
exhaustive: true,
823-
},
824-
{
825-
count: 551,
826-
data: null,
827-
isRefined: false,
828-
name: 'Samsung',
829-
escapedValue: 'Samsung',
830-
path: 'Samsung',
831-
exhaustive: true,
832-
},
833-
];
834-
835-
expect(facetValues).toEqual(expected);
836-
});

packages/algoliasearch-helper/test/spec/hierarchical-facets/simple-usage.js

Lines changed: 13 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -86,196 +86,20 @@ describe('hierarchical facets: simple usage', function () {
8686
client.search.mockClear();
8787
});
8888

89-
test('persistHierarchicalRootCount: false', function (done) {
90-
var helper = algoliasearchHelper(
91-
client,
92-
indexName,
93-
{
94-
hierarchicalFacets: [
95-
{
96-
name: 'categories',
97-
attributes: [
98-
'categories.lvl0',
99-
'categories.lvl1',
100-
'categories.lvl2',
101-
'categories.lvl3',
102-
],
103-
},
104-
],
105-
},
106-
{
107-
persistHierarchicalRootCount: false,
108-
}
109-
);
110-
111-
helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog');
112-
113-
var expectedHelperResponse = [
114-
{
115-
name: 'categories',
116-
count: null,
117-
isRefined: true,
118-
path: null,
119-
escapedValue: null,
120-
exhaustive: true,
121-
data: [
122-
{
123-
name: 'beers',
124-
path: 'beers',
125-
escapedValue: 'beers',
126-
count: 9,
127-
isRefined: true,
128-
exhaustive: true,
129-
data: [
130-
{
131-
name: 'IPA',
132-
path: 'beers > IPA',
133-
escapedValue: 'beers > IPA',
134-
count: 9,
135-
isRefined: true,
136-
exhaustive: true,
137-
data: [
138-
{
139-
name: 'Flying dog',
140-
path: 'beers > IPA > Flying dog',
141-
escapedValue: 'beers > IPA > Flying dog',
142-
count: 3,
143-
isRefined: true,
144-
exhaustive: true,
145-
data: null,
146-
},
147-
{
148-
name: 'Brewdog punk IPA',
149-
path: 'beers > IPA > Brewdog punk IPA',
150-
escapedValue: 'beers > IPA > Brewdog punk IPA',
151-
count: 6,
152-
isRefined: false,
153-
exhaustive: true,
154-
data: null,
155-
},
156-
],
157-
},
158-
{
159-
name: 'Pale Ale',
160-
path: 'beers > Pale Ale',
161-
escapedValue: 'beers > Pale Ale',
162-
count: 10,
163-
isRefined: false,
164-
exhaustive: true,
165-
data: null,
166-
},
167-
{
168-
name: 'Stout',
169-
path: 'beers > Stout',
170-
escapedValue: 'beers > Stout',
171-
count: 1,
172-
isRefined: false,
173-
exhaustive: true,
174-
data: null,
175-
},
176-
],
177-
},
178-
{
179-
name: 'fruits',
180-
path: 'fruits',
181-
escapedValue: 'fruits',
182-
count: 5,
183-
isRefined: false,
184-
exhaustive: true,
185-
data: null,
186-
},
187-
{
188-
name: 'sales',
189-
path: 'sales',
190-
escapedValue: 'sales',
191-
count: 20,
192-
isRefined: false,
193-
exhaustive: true,
194-
data: null,
195-
},
196-
],
197-
},
198-
];
199-
200-
helper.setQuery('a').search();
201-
202-
helper.once('result', function (event) {
203-
var queries = client.search.mock.calls[0][0];
204-
var hitsQuery = queries[0];
205-
var parentValuesQuery = queries[1];
206-
var fullParentsValuesQueries = queries.slice(2);
207-
208-
expect(queries.length).toBe(4);
209-
210-
expect(hitsQuery.params.facets).toEqual([
211-
'categories.lvl0',
212-
'categories.lvl1',
213-
'categories.lvl2',
214-
'categories.lvl3',
215-
]);
216-
expect(hitsQuery.params.facetFilters).toEqual([
217-
['categories.lvl2:beers > IPA > Flying dog'],
218-
]);
219-
220-
expect(parentValuesQuery.params.facets).toEqual([
221-
'categories.lvl0',
222-
'categories.lvl1',
223-
'categories.lvl2',
224-
]);
225-
expect(parentValuesQuery.params.facetFilters).toEqual([
226-
['categories.lvl1:beers > IPA'],
227-
]);
228-
229-
// Root
230-
expect(fullParentsValuesQueries[0].params.facets).toEqual(
231-
'categories.lvl0'
232-
);
233-
expect(fullParentsValuesQueries[0].params.facetFilters).toBe(undefined);
234-
235-
// Level 1
236-
expect(fullParentsValuesQueries[1].params.facets).toEqual(
237-
'categories.lvl1'
238-
);
239-
expect(fullParentsValuesQueries[1].params.facetFilters).toEqual([
240-
'categories.lvl0:beers',
241-
]);
242-
243-
expect(event.results.hierarchicalFacets).toEqual(expectedHelperResponse);
244-
expect(
245-
event.results.hierarchicalFacets.find((f) => f.name === 'categories')
246-
).toEqual(expectedHelperResponse[0]);
247-
248-
// we do not yet support multiple values for hierarchicalFacetsRefinements
249-
// but at some point we may want to open multiple leafs of a hierarchical menu
250-
// So we set this as an array so that we do not have to bump major to handle it
251-
expect(
252-
Array.isArray(helper.state.hierarchicalFacetsRefinements.categories)
253-
).toBeTruthy();
254-
done();
89+
test('simple usage', function (done) {
90+
var helper = algoliasearchHelper(client, indexName, {
91+
hierarchicalFacets: [
92+
{
93+
name: 'categories',
94+
attributes: [
95+
'categories.lvl0',
96+
'categories.lvl1',
97+
'categories.lvl2',
98+
'categories.lvl3',
99+
],
100+
},
101+
],
255102
});
256-
});
257-
258-
test('persistHierarchicalRootCount: true', function (done) {
259-
var helper = algoliasearchHelper(
260-
client,
261-
indexName,
262-
{
263-
hierarchicalFacets: [
264-
{
265-
name: 'categories',
266-
attributes: [
267-
'categories.lvl0',
268-
'categories.lvl1',
269-
'categories.lvl2',
270-
'categories.lvl3',
271-
],
272-
},
273-
],
274-
},
275-
{
276-
persistHierarchicalRootCount: true,
277-
}
278-
);
279103

280104
helper.toggleFacetRefinement('categories', 'beers > IPA > Flying dog');
281105

packages/instantsearch-core/src/__tests__/instantsearch.test.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -864,30 +864,7 @@ describe('start', () => {
864864
expect(algoliasearchHelper).toHaveBeenCalledWith(
865865
searchClient,
866866
indexName,
867-
undefined,
868-
{ persistHierarchicalRootCount: true }
869-
);
870-
});
871-
872-
it('creates a Helper with `persistHierarchicalRootCount` set to true when specified with a future flag', () => {
873-
const searchClient = createSearchClient();
874-
const indexName = 'indexName';
875-
const future = {
876-
persistHierarchicalRootCount: true,
877-
};
878-
const search = new InstantSearch({
879-
indexName,
880-
searchClient,
881-
future,
882-
});
883-
884-
search.start();
885-
886-
expect(algoliasearchHelper).toHaveBeenCalledWith(
887-
searchClient,
888-
indexName,
889-
undefined,
890-
{ persistHierarchicalRootCount: true }
867+
undefined
891868
);
892869
});
893870

0 commit comments

Comments
 (0)