Exemple #1
0
def test_field_facets(add_citation, add_subfield, add_subfield_document):
    """
    field_facets() should provide a list of label/value/count dicts.
    """

    f1 = Field.create(name='Field 1')
    f2 = Field.create(name='Field 2')
    f3 = Field.create(name='Field 3')

    sf1 = add_subfield(field=f1)
    sf2 = add_subfield(field=f2)
    sf3 = add_subfield(field=f3)

    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()
    Field_Index.es_insert()

    facets = field_facets()

    assert facets == [
        dict(label='Field 1', value=f1.id, count=3),
        dict(label='Field 2', value=f2.id, count=2),
        dict(label='Field 3', value=f3.id, count=1),
    ]
Exemple #2
0
def test_es_insert():

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

    Subfield.ingest()

    Field_Index.es_insert()

    for field in Field.select():

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

        assert doc['_source']['name'] == field.name
def field_facets():
    """
    Materialize field facets with counts.

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

    counts = Citation_Index.count_facets('field_id')
    return Field_Index.materialize_facets(counts)
def field_facets():

    """
    Materialize field facets with counts.

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

    counts = Citation_Index.count_facets("field_id")
    return Field_Index.materialize_facets(counts)
def test_field_facets(add_citation, add_subfield, add_subfield_document):

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

    f1 = Field.create(name="Field 1")
    f2 = Field.create(name="Field 2")
    f3 = Field.create(name="Field 3")

    sf1 = add_subfield(field=f1)
    sf2 = add_subfield(field=f2)
    sf3 = add_subfield(field=f3)

    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()
    Field_Index.es_insert()

    facets = field_facets()

    assert facets == [
        dict(label="Field 1", value=f1.id, count=3),
        dict(label="Field 2", value=f2.id, count=2),
        dict(label="Field 3", value=f3.id, count=1),
    ]