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

    # get the configuration so that we see what the field is
    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:
            # no %.. just make a combination
            expression = expression + " and " + searchwith
            response = Query(expression).search(collection=collection)
    else:  # either no expr or no searchwith.. but never mind about searchwith
        if expression:  # in this case: only expression
            response = Query(expression).search(collection=collection)
        else:
            # make a fake expression so that only records that have this field
            # will be returned
            fake_exp = "/.*/"
            if searchwith:
                fake_exp = searchwith
            response = Query("{0}:{1}".format(field, fake_exp)).search(
                collection=collection
            )

    # TODO wait for new search API for pagination
    response.body["size"] = 9999999
    values = []
    for record in response.records():
        value = record.get(field)
        if value:
            values.append(value)
    return values
def get_kbd_values_by_def ( confdict , searchwith = "" ) : 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 ) else : if 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
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