Add tests for context match sorting
Sort match elements externally

- Expose type distance from MatchElement
- Sort context matches in two passes