search: efficient permanode queries, sorted, and with a limit.

Change-Id: I7f8edfe3636ff3f1344ebb41e27d23073c630ff5