Perform a smart VRF search.

            The "smart" search function tries extract a query from
            a text string. This query is then passed to the search_vrf
            function, which performs the search.

def smart_search_vrf(self):
        """ Perform a smart VRF search.

            The "smart" search function tries extract a query from
            a text string. This query is then passed to the search_vrf
            function, which performs the search.
        """

        search_options = {}
        extra_query = None

        if 'query_id' in request.json:
            search_options['query_id'] = request.json['query_id']

        if 'max_result' in request.json:
            search_options['max_result'] = request.json['max_result']

        if 'offset' in request.json:
            search_options['offset'] = request.json['offset']

        if 'vrf_id' in request.json:
            extra_query = {
                    'val1': 'id',
                    'operator': 'equals',
                    'val2': request.json['vrf_id']
                }

        try:
            result = VRF.smart_search(request.json['query_string'],
                search_options, extra_query
                )
            # Remove error key in result from backend as it interferes with the
            # error handling of the web interface.
            # TODO: Reevaluate how to deal with different types of errors; soft
            # errors like query string parser errors and hard errors like lost
            # database.
            del result['error']
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

        return json.dumps(result, cls=NipapJSONEncoder)