Skip to content

Conversation

@bidoubiwa
Copy link
Contributor

fixes: #797

Maybe related: #776
Maybe related: #825

keepZeroFacets was not working when placeholderSearch was set to false and when using the routing system.

This PR fixes the issue.

@bidoubiwa bidoubiwa added the bug Something isn't working label Aug 29, 2022
Comment on lines +98 to +121
const response2 = await searchClient.search([
{
indexName: 'movies',
params: {
facets: ['genres'],
query: 'no results',
},
},
])

expect(response2.results[0].facets).toEqual({
genres: {
Action: 0,
Adventure: 0,
Animation: 0,
Comedy: 0,
Crime: 0,
Drama: 0,
'Science Fiction': 0,
Thriller: 0,
},
})
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this, because you have the same setup/exercise in the test below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually a difference for me!
The first tests:

  • Makes a search with no query
  • Should cache the default distribution correctly
  • Makes a search with the same searchClient as before but with a query that would return 0 documents
  • Checks if every facet is correctly set to 0

Second test:

  • Does a search with a query that would return 0 documents
  • Should cache the default distribution when none has been set before
  • Checks if every facet is correctly set to 0

There is a cache system between the multiple calls on the same search client. These two tests ensure they are helping each other.
The tests that ensure that when doing two call on my search client only triggers the default facetdistribution call only once is tested here: #830 (comment). In this test we are calling two time searchClient.search. During the first search we make two requests to meilisearch, one for the default facet distribution, one for the actual search. During the second search on the same searchClient the default facet distribution should already be cached and only the actual search request should be made, thus 3 calls.

clientAgents: [`Meilisearch instant-meilisearch (v${PACKAGE_VERSION})`],
})
expect(mockedSearch).toHaveBeenCalledTimes(2)
expect(mockedSearch).toHaveBeenCalledTimes(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have +1 calls now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the first call always sets up the default facet distribution by making a call with zero filters (except for the facet field) to ensure we have the facet distribution of an empty search not impacted by any filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the scenario tested in the tests:
All of them are possible scenarios that were causing bugs and that I want to ensure are working correctly now

  // Without facets
  // Without keepZeroFacets
  // With placeholderSearch
  // With empty query
// Without facets
  // With keepZeroFacets
  // With placeholderSearch
  // With empty query
  // With facets
  // without keepZeroFacets
  // without placeholderSearch
  // With multiple search (empty and no results expected)
  // With facets
  // without keepZeroFacets
  // with placeholderSearch
  // With empty query
  // With facets
  // with keepZeroFacets
  // with placeholderSearch
  // With multiple search (empty and no results expected)
  // With facets
  // with keepZeroFacets
  // without placeholderSearch
  // With multiple search (empty and no results expected)
  // With facets
  // with keepZeroFacets
  // with placeholderSearch
  // Without multiple search
  // Without query expecting no results

mdubus
mdubus previously approved these changes Aug 31, 2022
Copy link
Member

@mdubus mdubus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥

brunoocasali
brunoocasali previously approved these changes Aug 31, 2022
Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

@bidoubiwa bidoubiwa dismissed stale reviews from brunoocasali and mdubus via 67d5ca8 August 31, 2022 14:55
@bidoubiwa
Copy link
Contributor Author

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Aug 31, 2022

@meili-bors meili-bors bot merged commit a2e6a49 into main Aug 31, 2022
@meili-bors meili-bors bot deleted the fix_default_zero_facets branch August 31, 2022 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

keepZeroFacets interaction with cache when pre-populating results does not work

4 participants