rasteiner / k3-whenquery

Conditionally show fields and sections. Better.
MIT License
64 stars 1 forks source link

search operator #1

Closed rasteiner closed 2 years ago

rasteiner commented 2 years ago

I'm not sure on the ordering of the operands... Should it be: haystack =~ needle or needle =~ haystack? Or needle =~ haystack and haystack ~= needle? Or is that too confusing?

Really open for suggestions and discussion

rasteiner commented 2 years ago

Also... Array on Array search. Should it return true when all elements are found (like now) or if "some" of the elements are found? Or maybe return the "number of found elements"?

gearsdigital commented 2 years ago

What about to introduce a custom expression language?

For example:haystay OR needle or haystay NE needle.

  1. eq = ===
  2. ne = !==
  3. or = ||
  4. lt = >
  5. lte = >=
  6. ...

That is probaly (better) understandable for users without devlopment background. You could use even full words like equal.

rasteiner commented 2 years ago

The currently supported comparison and equality operators are: =, !=, <, <=, >, >= and =~ (the search operator, the one this issue is about). I don't really have many doubts about these other ones, technically they're much easier to parse than "keywords" and they eliminate the chance of ambiguity between identifiers and keywords (like if someone calls their textfield "equal"). There are ways to solve this, like doing stuff like :equal: or :lte:, but I don't feel like they would be easier to understand for the majority of people editing yml files.

This issue is only about the =~ operator, for which there isn't really an established language I know to copy from. The problem it solves is that the expression language here doesn't allow function calls, therefore without this special operator it's not possible to do something like textfield.includes('foo') to check if "textfield" contains "foo".

But maybe I actually could do keywords for different search operations. Like textfield :include: "foo", so that I could cover different search methods, like for example textfield :start: "foo", array :all: [1,2,3], array :some: [1,2,3], etc...

rasteiner commented 2 years ago

The problem it solves is that the expression language here doesn't allow function calls

Another option would be to just allow function calls, maybe restricted to an "allow list"