Skip to content

fix(disjunctive): prefer values of main query for facet count #6445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var lib = {

mod[attribute] = facetRefinement;

return defaultsPure({}, mod, refinementList);
return defaultsPure(mod, refinementList);
},
/**
* Removes refinement(s) for an attribute:
Expand Down
3 changes: 0 additions & 3 deletions packages/algoliasearch-helper/src/SearchParameters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,6 @@ SearchParameters.prototype = {

return this.setQueryParameters({
hierarchicalFacetsRefinements: defaultsPure(
{},
mod,
this.hierarchicalFacetsRefinements
),
Expand Down Expand Up @@ -1241,7 +1240,6 @@ SearchParameters.prototype = {
mod[facet] = [path];
return this.setQueryParameters({
hierarchicalFacetsRefinements: defaultsPure(
{},
mod,
this.hierarchicalFacetsRefinements
),
Expand All @@ -1262,7 +1260,6 @@ SearchParameters.prototype = {
mod[facet] = [];
return this.setQueryParameters({
hierarchicalFacetsRefinements: defaultsPure(
{},
mod,
this.hierarchicalFacetsRefinements
),
Expand Down
4 changes: 2 additions & 2 deletions packages/algoliasearch-helper/src/SearchResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ function SearchResults(state, results, options) {

self.disjunctiveFacets[position] = {
name: dfacet,
data: defaultsPure({}, facetResults, dataFromMainRequest),
data: defaultsPure(dataFromMainRequest, facetResults),
exhaustive: result.exhaustiveFacetsCount,
};
assignFacetStats(
Expand Down Expand Up @@ -927,7 +927,7 @@ SearchResults.prototype.getFacetValues = function (attribute, opts) {
return undefined;
}

var options = defaultsPure({}, opts, {
var options = defaultsPure(opts, {
sortBy: SearchResults.DEFAULT_SORT,
// if no sortBy is given, attempt to sort based on facetOrdering
// if it is given, we still allow to sort via facet ordering first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,24 @@ test('getFacetValues(hierarchical) when current state is different to constructo

expect(facetValues).toEqual(expected);
});

test('getFacetValues(facetName) prefers the "main" facet result', function () {
var data = require('./getFacetValues/disjunctive-non-exhaustive.json');
var searchParams = new SearchParameters(data.state);
var result = new SearchResults(searchParams, data.content.results);

var facetValues = result.getFacetValues('brand');

var expected = [
{ count: 1000, isRefined: true, name: 'Apple', escapedValue: 'Apple' },
{
count: 551,
isRefined: false,
name: 'Insignia™',
escapedValue: 'Insignia™',
},
{ count: 511, isRefined: false, name: 'Samsung', escapedValue: 'Samsung' },
];

expect(facetValues).toEqual(expected);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"content": {
"results": [
{
"hits": [],
"nbHits": 1000,
"page": 0,
"nbPages": 20,
"hitsPerPage": 0,
"processingTimeMS": 1,
"facets": {
"brand": {
"Apple": 1000
}
},
"exhaustiveFacetsCount": true,
"query": "",
"params": "query=&maxValuesPerFacet=3&page=0&facets=%5B%22brand%22%5D&tagFilters=&facetFilters=%5B%5B%22brand%3AApple%22%5D%5D",
"index": "instant_search"
},
{
"hits": [
{
"objectID": "1696302"
}
],
"nbHits": 10000,
"page": 0,
"nbPages": 1000,
"hitsPerPage": 1,
"processingTimeMS": 1,
"facets": {
"brand": {
"Insignia™": 551,
"Samsung": 511,
"Apple": 1
}
},
"exhaustiveFacetsCount": false,
"query": "",
"params": "query=&maxValuesPerFacet=3&page=0&hitsPerPage=1&attributesToRetrieve=%5B%5D&attributesToHighlight=%5B%5D&attributesToSnippet=%5B%5D&tagFilters=&facets=brand",
"index": "instant_search"
}
]
},
"state": {
"index": "instant_search",
"query": "",
"facets": [],
"disjunctiveFacets": ["brand"],
"hierarchicalFacets": [],
"facetsRefinements": {},
"facetsExcludes": {},
"disjunctiveFacetsRefinements": {
"brand": ["Apple"]
},
"numericRefinements": {},
"tagRefinements": [],
"hierarchicalFacetsRefinements": {},
"maxValuesPerFacet": 3,
"page": 0
},
"error": null
}
Loading