Refs #10026 fix algorithm and add unit and doc tests
Merge remote-tracking branch 'origin/feature/10026_SortByQVectors_fix'