Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files": [
{
"path": "packages/algoliasearch-helper/dist/algoliasearch.helper.js",
"maxSize": "42 kB"
"maxSize": "42.25 kB"
},
{
"path": "packages/algoliasearch-helper/dist/algoliasearch.helper.min.js",
Expand All @@ -18,19 +18,19 @@
},
{
"path": "packages/react-instantsearch-core/dist/umd/ReactInstantSearchCore.min.js",
"maxSize": "51.75 kB"
"maxSize": "52 kB"
},
{
"path": "packages/react-instantsearch/dist/umd/ReactInstantSearch.min.js",
"maxSize": "65.75 kB"
"maxSize": "66 kB"
},
{
"path": "packages/vue-instantsearch/vue2/umd/index.js",
"maxSize": "69.25 kB"
"maxSize": "70 kB"
},
{
"path": "packages/vue-instantsearch/vue3/umd/index.js",
"maxSize": "69.75 kB"
"maxSize": "70 kB"
},
{
"path": "packages/vue-instantsearch/vue2/cjs/index.js",
Expand Down
16 changes: 15 additions & 1 deletion packages/algoliasearch-helper/src/algoliasearch.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,28 @@ AlgoliaSearchHelper.prototype.searchForFacetValues = function (
query: query,
});

var hide =
(this.lastResults &&
this.lastResults.index === state.index &&
this.lastResults.renderingContent &&
this.lastResults.renderingContent.facetOrdering &&
this.lastResults.renderingContent.facetOrdering.values &&
this.lastResults.renderingContent.facetOrdering.values[facet] &&
this.lastResults.renderingContent.facetOrdering.values[facet].hide) ||
[];

return searchForFacetValuesPromise.then(
function addIsRefined(content) {
self._currentNbQueries--;
if (self._currentNbQueries === 0) self.emit('searchQueueEmpty');

content = Array.isArray(content) ? content[0] : content;

content.facetHits.forEach(function (f) {
content.facetHits.forEach(function (f, i) {
if (hide.indexOf(f.value) > -1) {
content.facetHits.splice(i, 1);
return;
}
f.escapedValue = escapeFacetValue(f.value);
f.isRefined = isDisjunctive
? state.isDisjunctiveFacetRefined(facet, f.escapedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,168 @@ test('escaped value is marked as refined', function () {
});
});
});

test('hides a facet value that is hidden according to `renderingContent`', function () {
var fakeClient = {
addAlgoliaAgent: function () {},
search: function () {
return Promise.resolve({
results: [
{
index: 'index',
renderingContent: {
facetOrdering: {
values: {
facet: {
hide: ['hidden'],
},
},
},
},
},
],
});
},
searchForFacetValues: function () {
return Promise.resolve([
{
exhaustiveFacetsCount: true,
facetHits: [
{
count: 318,
highlighted: 'something',
value: 'something',
},
{
count: 1,
highlighted: 'hidden',
value: 'hidden',
},
],
processingTimeMS: 3,
},
]);
},
};

var helper = algoliasearchHelper(fakeClient, 'index', {
disjunctiveFacets: ['facet'],
renderingContent: {
facetValues: [
{
name: 'something',
isRefined: true,
},
],
},
});

return new Promise(function (res) {
helper.search();
helper.once('result', res);
})
.then(function () {
return helper.searchForFacetValues('facet', 'k', 1);
})
.then(function (content) {
expect(content).toEqual({
exhaustiveFacetsCount: true,
processingTimeMS: 3,
facetHits: [
{
count: 318,
highlighted: 'something',
isRefined: false,
escapedValue: 'something',
value: 'something',
},
],
});
});
});

test('does not hide if last results are for another index', function () {
var fakeClient = {
addAlgoliaAgent: function () {},
search: function () {
return Promise.resolve({
results: [
{
index: 'index',
renderingContent: {
facetOrdering: {
values: {
facet: {
hide: ['hidden'],
},
},
},
},
},
],
});
},
searchForFacetValues: function () {
return Promise.resolve([
{
exhaustiveFacetsCount: true,
facetHits: [
{
count: 318,
highlighted: 'something',
value: 'something',
},
{
count: 1,
highlighted: 'hidden',
value: 'hidden',
},
],
processingTimeMS: 3,
},
]);
},
};

var helper = algoliasearchHelper(fakeClient, 'index', {
disjunctiveFacets: ['facet'],
renderingContent: {
facetValues: [
{
name: 'something',
isRefined: true,
},
],
},
});

return new Promise(function (res) {
helper.search();
helper.once('result', res);
})
.then(function () {
return helper.searchForFacetValues('facet', 'k', 1, { index: 'index2' });
})
.then(function (content) {
expect(content).toEqual({
exhaustiveFacetsCount: true,
processingTimeMS: 3,
facetHits: [
{
count: 318,
highlighted: 'something',
isRefined: false,
escapedValue: 'something',
value: 'something',
},
{
count: 1,
highlighted: 'hidden',
isRefined: false,
escapedValue: 'hidden',
value: 'hidden',
},
],
});
});
});