countsquaresfilter takes a range and a set filter as its arguments:
countsquares range set-filter
The filter returns true if the number of the squares in the set denoted by its set filter argument lies within its range.
countsquares 2 4 Pis true when the current position has between 2 and 4 white pawns.
sort countsquares 1 64 attack (Q _)will sort games by the maximum number of empty squares attacked by a white Queen. This is because
attack (Q _)represents the set of empty squares attacked by a white Queen in the current position.