We want to have a NEAREST spatial predicate in ECQL, with the usage being something similar to NEAREST(geom_column,POINT(21707 6558912),10), returning the nearest 10 features to POINT. Hopefully, where the database provides optimisations (e.g. PostGIS true KNN), that can be used.
Usage could look like cql_filter=my_col IN ('X', 'Y') AND pgNearest(POINT(16.36 48.205),30)=true AND my_other_col > 0 ?
The implementation will assume postgis > 9.5 and availability of primary key and must turn the function into a subquery so that we can express that as part of the where clause (encoding it as part of the top level order would require too many code changes with broad consequences):