def get_kbd_values_by_def(confdict, searchwith=''):
    """Return a list of values by searching a dynamic kb.

    :param confdict: dictionary with keys "field", "expression"
        and "collection" name
    :param searchwith: a term to search with
    :return: list of values
    """
    from invenio_search.api import Query
    if not confdict:
        return []
    if 'field' not in confdict:
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ''
    if 'collection' in confdict:
        collection = confdict['collection']
    if searchwith and expression:
        if expression.count('%') > 0:
            expression = expression.replace('%', searchwith)
            response = Query(expression).search(collection=collection)
        else:
            expression = expression + ' and ' + searchwith
            response = Query(expression).search(collection=collection)
    elif expression:
        response = Query(expression).search(collection=collection)
    else:
        fake_exp = '/.*/'
        if searchwith:
            fake_exp = searchwith
        response = Query('{0}:{1}'.format(field, fake_exp)).search(collection
            =collection)
    response.body['size'] = 9999999
    values = []
    for record in response.records():
        value = record.get(field)
        if value:
            values.append(value)
    return values
