Move more autocomplete logic from web to api, fixes #257