Search improvements

Some refactoring, rename text parameter to query, ability to specify
page number, some additional checks.