-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix keepZeroFacets on disjunctive facet search #918
Conversation
if (searchContext.keepZeroFacets) { | ||
const cachedFacets = extractFacets(searchContext, searchParams) | ||
|
||
// Add missing facets back into facetDistribution | ||
searchResponse.facetDistribution = addMissingFacets( | ||
cachedFacets, | ||
searchResponse.facetDistribution | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved as it should be in the response adapter
290371a
to
a4a845a
Compare
// Cache first facets distribution of the instantMeilisearch instance | ||
// Needed to add in the facetDistribution the fields that were not returned | ||
// When the user sets `keepZeroFacets` to true. | ||
if (defaultFacetDistribution === undefined) { | ||
defaultFacetDistribution = await cacheFirstFacetDistribution( | ||
searchResolver, | ||
searchContext | ||
) | ||
searchContext.defaultFacetDistribution = defaultFacetDistribution | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed to its own file init-facet-distribution.ts
let defaultFacetDistribution: FacetDistribution | ||
let initialFacetDistribution: Record<string, FacetDistribution> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed name to better understand what it contains
return { | ||
results: [adaptedSearchResponse], | ||
} | ||
return adaptedSearchResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return value was changed as this is legacy that made the process weird
searchContext, | ||
initialFacetDistribution[searchRequest.indexName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed initialFacetDistribution
from the searchContext
as it is not correlated to the current search request but as value for the whole instance
@@ -33,7 +31,6 @@ export function createSearchContext( | |||
sort: sortByArray.join(':') || '', | |||
indexUid, | |||
pagination: paginationState, | |||
defaultFacetDistribution: defaultFacetDistribution || {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed defaultFacetDistribution
from the searchContext
as it is not correlated to the current search request but as value for the whole instance.
export type SearchContext = Omit<InstantSearchParams, 'insideBoundingBox'> & | ||
InstantSearchParams & { | ||
defaultFacetDistribution: FacetDistribution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed defaultFacetDistribution
from the searchContext
as it is not correlated to the current search request but as value for the whole instance.
@@ -73,9 +70,10 @@ export type InstantSearchPagination = { | |||
nbPages: number | |||
} | |||
|
|||
export type Facets = string | string[] | undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creation of own Facets
type as the one from instant-search does not represent the reality.
instant-search
may provide only a string
as a Facets
but the type states that it only accepts string[] | undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this issue
cf5ffe0
to
0d1b9ea
Compare
@@ -5,7 +5,6 @@ import { | |||
SearchCacheInterface, | |||
MeiliSearchParams, | |||
} from '../../types' | |||
import { addMissingFacets, extractFacets } from './filters' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed as facet managements has changed and moved to the response adapter
63cc33a
to
8f1e01c
Compare
8f1e01c
to
78d8870
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments that can be done in a new PR maybe, I don't want to block the merge :)
LGTM!
src/adapter/search-response-adapter/facet-distribution-adapter.ts
Outdated
Show resolved
Hide resolved
2927583
to
40a13a7
Compare
bors merge |
Since introducing the multi-index search here #888 the setting
keepZeroFacets
was broken.This PR introduces the fix to this issue
Dec-13-2022.17-12-15.mp4
What was done in this pr:
defaultFacetDistribution
is renamedinitialFacetDistribution
and contains the distribution of an index without any other requestsPlaygrounds:
SingleIndex
with keepZeroFacetsMultiIndex
with keepZeroFacets