Example #1
0
def lcc_transform(raw):
    """
    Transform the lcc search field value
    :param str raw:
    :rtype: str
    """
    # e.g. lcc:[NC1 TO NC1000] to lcc:[NC-0001.00000000 TO NC-1000.00000000]
    # for proper range search
    m = re_range.match(raw)
    if m:
        lcc_range = [m.group('start').strip(), m.group('end').strip()]
        normed = normalize_lcc_range(*lcc_range)
        return f'[{normed[0] or lcc_range[0]} TO {normed[1] or lcc_range[1]}]'
    elif '*' in raw and not raw.startswith('*'):
        # Marshals human repr into solr repr
        # lcc:A720* should become A--0720*
        parts = raw.split('*', 1)
        lcc_prefix = normalize_lcc_prefix(parts[0])
        return (lcc_prefix or parts[0]) + '*' + parts[1]
    else:
        normed = short_lcc_to_sortable_lcc(raw.strip('"'))
        if normed:
            use_quotes = ' ' in normed or raw.startswith('"')
            return ('"%s"' if use_quotes else '%s*') % normed

    # If none of the transforms took
    return raw
Example #2
0
def test_invalid_lccs(text, name):
    assert short_lcc_to_sortable_lcc(text) is None
Example #3
0
def test_wagner_2019_to_sortable(sortable_lcc, short_lcc, name):
    assert short_lcc_to_sortable_lcc(short_lcc) == sortable_lcc
Example #4
0
def test_to_sortable(sortable_lcc, raw_lcc, short_lcc, name):
    assert short_lcc_to_sortable_lcc(raw_lcc) == sortable_lcc