def test_subfield_facets(add_citation, add_subfield, add_subfield_document):

    """
    subfield_facets() should provide a list of label/value/count dicts.
    """

    sf1 = add_subfield(name="Subfield 1")
    sf2 = add_subfield(name="Subfield 2")
    sf3 = add_subfield(name="Subfield 3")

    for i in range(3):
        c = add_citation()
        add_subfield_document(subfield=sf1, document=c.document)

    for i in range(2):
        c = add_citation()
        add_subfield_document(subfield=sf2, document=c.document)

    for i in range(1):
        c = add_citation()
        add_subfield_document(subfield=sf3, document=c.document)

    Citation_Index.es_insert()
    Subfield_Index.es_insert()

    facets = subfield_facets()

    assert facets == [
        dict(label="Subfield 1", value=sf1.id, count=3),
        dict(label="Subfield 2", value=sf2.id, count=2),
        dict(label="Subfield 3", value=sf3.id, count=1),
    ]
Beispiel #2
0
def test_subfield_facets(add_citation, add_subfield, add_subfield_document):
    """
    subfield_facets() should provide a list of label/value/count dicts.
    """

    sf1 = add_subfield(name='Subfield 1')
    sf2 = add_subfield(name='Subfield 2')
    sf3 = add_subfield(name='Subfield 3')

    for i in range(3):
        c = add_citation()
        add_subfield_document(subfield=sf1, document=c.document)

    for i in range(2):
        c = add_citation()
        add_subfield_document(subfield=sf2, document=c.document)

    for i in range(1):
        c = add_citation()
        add_subfield_document(subfield=sf3, document=c.document)

    Citation_Index.es_insert()
    Subfield_Index.es_insert()

    facets = subfield_facets()

    assert facets == [
        dict(label='Subfield 1', value=sf1.id, count=3),
        dict(label='Subfield 2', value=sf2.id, count=2),
        dict(label='Subfield 3', value=sf3.id, count=1),
    ]
def test_es_insert():
    """
    Subfield_Index.es_insert() should load all fields into Elasticsearch
    """

    Subfield.ingest()

    Subfield_Index.es_insert()

    for sf in Subfield.select():

        doc = config.es.get(
            index='subfield',
            id=sf.id,
        )

        assert doc['_source']['name'] == sf.name
def test_es_insert():

    """
    Subfield_Index.es_insert() should load all fields into Elasticsearch
    """

    Subfield.ingest()

    Subfield_Index.es_insert()

    for sf in Subfield.select():

        doc = config.es.get(
            index='subfield',
            id=sf.id,
        )

        assert doc['_source']['name'] == sf.name
def subfield_facets():
    """
    Materialize subfield facets with counts.

    Returns:
        dict: {label, value, count}
    """

    counts = Citation_Index.count_facets('subfield_id')
    return Subfield_Index.materialize_facets(counts)
def subfield_facets():

    """
    Materialize subfield facets with counts.

    Returns:
        dict: {label, value, count}
    """

    counts = Citation_Index.count_facets("subfield_id")
    return Subfield_Index.materialize_facets(counts)