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

Add filter support for conjunctions (and), disjunctions (or), and negations (not) #49

Open
bullfight opened this issue Mar 27, 2023 · 0 comments

Comments

@bullfight
Copy link

Hopefully this is welcome! I am really impressed with what you are doing here, I started on a little prototype for a filtering system myself, but am nowhere as far along as this.

I want to suggest a feature and a data structure for adding some really cool functionality to filters.

Problem

The current approach for filters uses conjunctions by default, but it is often useful to combine conjunctions and disjunctions together.

Solution

Add support for conjunctions (and), and disjunctions (or).

This can be supported by recursively nesting query filters via "value":

Example conjunction with a disjunction:

filters: [
  %{
    "filter" => "and",
    "value" => [
      %{
        "column" => "year",
        "filter" => "equal",
        "value" => 2010
      },
      {
        "filter" => "or",
        "value" => [
          %{
            "column" => "country",
            "filter" => "equal",
            "value" => "Angola"
          },
          %{
            "column" => "country",
            "filter" => "equal",
            "value" => "Algeria"
          }
        ]
      }
    ]
  }
]

With this you can combine and nest conjunctions, and disjunctions as needed. It also works well for building a UI with nested objects.

Negations
I also wanted to suggest supporting negations directly for any given filter operator, e.g

%{
  "filter" => "not equal",
}

becomes

%{
  "filter" => "equal",
  "negate" => true,
}

Negations then become a really simple toggle for any given filter. In your code you then can define a single operation direction, and the inverse is just a negation.

P.S.
You can see an example of how this might work in this repo. I'm a novice at elixir, but I think this is illustrative of the idea.

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