Skip to content

fix error when filter value not found in items set #130

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 3 commits into from
Sep 14, 2023
Merged

fix error when filter value not found in items set #130

merged 3 commits into from
Sep 14, 2023

Conversation

aurelienroux
Copy link
Contributor

It’s my first time contributing to a public repo so let me know if anything needs to be corrected. I added a test to explain the specific usecase covered.

This pr is adding the possibility of having a non existing value in the filters. We want to have a predefined set of filters, but also having the possibility that the filtered data (items) will sometimes not include one of the options.

example: possible filters for categories would be comedy, drama or thriller by default, but the related items would only contains comedy or drama categories. Added a fallback to an empty FastBitset when needed, so it would not break.

Let me know if any changes are necessary and thanks for the lib!

@cigolpl
Copy link
Member

cigolpl commented Sep 12, 2023

Thank you for your first contribution!

In my opinion we should be returning zero results instead of ignoring not existing filters like in your case "thriller".

The reason is - it directly informs the user that their criteria didn't match anything, prompting them to reconsider their filter choices and users won't be under the impression that they successfully applied all filters when in reality some were invalid.

Would it work with your use case ?

@aurelienroux
Copy link
Contributor Author

Actually, this is correct when conjoncture:true.
But when false, ItemsJS applies the OR operator between filter values, so a non-existing value should just be ignored.
I added both tests with different conjunctions to ensure we apply the proper behaviour.

WDYT ?

Copy link
Member

@cigolpl cigolpl left a comment

Choose a reason for hiding this comment

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

I've finished reviewing your PR. Once you've addressed the feedback, please let me know so I can take a final look.


it('makes search with non existing filter value with conjunction false should return results', function test(done) {

configuration.aggregations.category.conjunction = false;
Copy link
Member

Choose a reason for hiding this comment

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

This test modifies a shared configuration value (configuration.aggregations.category.conjunction). For test independence, please consider:

  1. Using a dedicated configuration copy just for this test, or
  2. Resetting the configuration to its initial state post-test.

This approach ensures tests don't inadvertently influence each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good.
I added a localConfiguration from a Lodash clone so it's clearer those 2 tests are set on a different config. Let me know if it works for you.

@cigolpl cigolpl merged commit d0a63a6 into itemsapi:master Sep 14, 2023
@cigolpl
Copy link
Member

cigolpl commented Sep 14, 2023

Looks great to me! Merging now.

@cigolpl
Copy link
Member

cigolpl commented Sep 14, 2023

@aurelienroux
Copy link
Contributor Author

awesome, thanks for your help 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants