Skip to content
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

Question: Disjunctive Filters between Numeric and Facets #139

Open
nerder opened this issue Jul 1, 2024 · 1 comment
Open

Question: Disjunctive Filters between Numeric and Facets #139

nerder opened this issue Jul 1, 2024 · 1 comment

Comments

@nerder
Copy link

nerder commented Jul 1, 2024

We are trying to create the following query:

status:active OR lastAttendedDate > 1700000000000

Our code looks like this:

filterState.add(FilterGroupID.or('someGroup'), [
  Filter.facet('status', "active"),
  Filter.comparison('date', NumericOperator.greaterOrEquals, 170000000),
]);

When we look at the query parameters produced tho, we got this status:active AND lastAttendedDate > 1700000000000

By looking at the internal code:

  String? sql(Set<FilterGroup> filterGroups) {
    final groups = filterGroups.whereNot((element) => element.isEmpty);
    if (groups.isEmpty) return null;
    return groups.map(_sqlGroup).join(' AND ');
  }

This function seems to be adding an AND between multiple-group, but in our case what is not obvious to us is why our filter is considered to be made of 2 groups, where we only have one. This seems to happen only when we use Filter.comparison or Filter.range.

Our expectation is that when we add a Disjuctive group that will be respected, but in this case it seems to be forced into a conjuctive one, why is that?

Some additional info is that all our facets are configured as filters only in the dashboard.

Any help?

@nerder
Copy link
Author

nerder commented Jul 1, 2024

Ok it seems like that this is intended as per the documentation: https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/in-depth/combining-boolean-operators/#mixed-filter-types-in-or-conditions

Nonetheless it's quite an unexpected behaviour, I'd rather throw an error that point you to the documentation that "automagically" fix the query.

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

No branches or pull requests

1 participant