api: add pagination support for search

This also improves the search algorithm.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>