count items matching a rule