port state search function to the new api

The function field has been ported to the new API, so I ported the
search method as well. It looks nicer because we do not have to iterate
over all search terms on the new API.
add docstring