Use numOrds rather than numDocs as upperbound for sorting

Closes #2773