Search with numerical expressions (working fork)

New search node “math:

I have implemented a search node which makes it possible to filter cards by comparing fields and properties numerically (code on Github).


math:[mathematical expression][<|>|=|>=|<=|!=][mathematical expression]

The expressions may contain numbers, the operators [+|-|*|/], the property variables [due|ivl|ease|lapses|reps] or any other string which will be interpreted as a field name.


  1. "math:Freq 1<Freq 2"
    ... finds notes which have fields “Freq 1” and “Freq 2” and where the value in the former is numerically smaller than the one in the latter.
  2. math:due<0.05*ivl
    ... finds cards which have less than 5% of their current interval remaining (useful for studying ahead).
  3. math:lapses>0.2*reps
    ... finds cards where lapses account for more than 20% of the reviews.


The code is fully functional and ready to go. There are a few features left that might be nice to have, though: *
  • Escape characters (so field names containing “-”, “!” etc. can be used) :white_check_mark: *
  • Parantheses :white_check_mark: *
  • Real division (currently, 10/3 evaluates to 3) :white_check_mark: *
  • Maybe filtering out notes with non-numeric content in a specified field (oversimplified, non-numeric strings are interpreted as 0 by SQL)
  • Maybe multiple equation operators (math:10<reps<20) *


If you have any use cases where this functionality would be advantageous or can think of a feature that would add even more benefit to it, I would love to hear about it.

And now the question of questions: Would you accept a pull request once the aforementioned issues are addressed, @dae ?

* edited lines

At first glance your code looks good! My only concern is whether there’s much demand for this, as it’s more complicated than any of the existing queries we have, and will need to be maintained moving forward. For onlookers, if you’d find this useful, would you mind jumping in with what you’d use it for?

1 Like

Well, to be fair, RegEx search is somewhat more complicated. :wink:
But jokes aside, yes, it would add quite an amount of code to the parser and sqlwriter files, especially with the todos mentioned above.
I definitely plan on sticking around and helping to maintain the parts I’ve contributed to but I’m aware that from your point of view, there’s no reason to rely on that.

1 Like