Skip to content

Commit

Permalink
Merge #918
Browse files Browse the repository at this point in the history
918: Fix keepZeroFacets on disjunctive facet search r=bidoubiwa a=bidoubiwa

Since introducing the multi-index search here #888 the setting `keepZeroFacets` was broken.

This PR introduces the fix to this issue


https://user-images.githubusercontent.com/33010418/207385436-e49ded20-e76b-4974-86de-904cfeecfbd7.mp4

What was done in this pr:

- keepZeroFacet management has been moved to the response adapter instead of the request adapter
- Filtering methods and filtering tests were removed as the new facet distribution management has completely changed
- `defaultFacetDistribution` is renamed `initialFacetDistribution` and contains the distribution of an index without any other requests
- Initialization of facet distribution was moved from client to its own file


Playgrounds:
- New SingleMovieIndex playground to create a new environment for testing
- Updated `SingleIndex` with keepZeroFacets
- Updated `MultiIndex` with keepZeroFacets


Co-authored-by: Charlotte Vermandel <[email protected]>
  • Loading branch information
meili-bors[bot] and bidoubiwa authored Dec 15, 2022
2 parents 7951ab5 + 40a13a7 commit f836516
Show file tree
Hide file tree
Showing 17 changed files with 867 additions and 356 deletions.

This file was deleted.

71 changes: 0 additions & 71 deletions src/adapter/search-request-adapter/__tests__/filter-cache.tests.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { adaptSearchParams } from '../search-params-adapter'
import { MatchingStrategies } from '../../../types'
import { MatchingStrategies, SearchContext } from '../../../types'

const DEFAULT_CONTEXT = {
const DEFAULT_CONTEXT: SearchContext = {
indexUid: 'test',
pagination: { page: 0, hitsPerPage: 6, finite: false },
defaultFacetDistribution: {},
placeholderSearch: true,
keepZeroFacets: false,
}
Expand Down
128 changes: 0 additions & 128 deletions src/adapter/search-request-adapter/filters.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/adapter/search-request-adapter/search-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SearchCacheInterface,
MeiliSearchParams,
} from '../../types'
import { addMissingFacets, extractFacets } from './filters'

/**
* @param {ResponseCacher} cache
Expand Down Expand Up @@ -42,16 +41,6 @@ export function SearchResolver(
.index(searchContext.indexUid)
.search(searchContext.query, searchParams)

if (searchContext.keepZeroFacets) {
const cachedFacets = extractFacets(searchContext, searchParams)

// Add missing facets back into facetDistribution
searchResponse.facetDistribution = addMissingFacets(
cachedFacets,
searchResponse.facetDistribution
)
}

// Cache response
cache.setEntry<MeiliSearchResponse>(key, searchResponse)

Expand Down
Loading

0 comments on commit f836516

Please sign in to comment.