def test_merge_included(add_institution, add_citation): """ When ids are passed for institutions that fall outside of the default page, merge the extra facets into the baseline ranking. """ i1 = add_institution(name='Institution 1') i2 = add_institution(name='Institution 2') i3 = add_institution(name='Institution 3') for i in range(3): c = add_citation() Institution_Document.create(institution=i1, document=c.document) for i in range(2): c = add_citation() Institution_Document.create(institution=i2, document=c.document) for i in range(1): c = add_citation() Institution_Document.create(institution=i3, document=c.document) Citation_Index.es_insert() Institution_Index.es_insert() facets = institution_facets(depth=2, include=[i2.id, i3.id]) assert facets == [ dict(label='Institution 1', value=i1.id, count=3), dict(label='Institution 2', value=i2.id, count=2), # Dedupe 2. dict(label='Institution 3', value=i3.id, count=1), # Append 3. ]
def test_institution_facets(add_institution, add_citation): """ institution_facets() should provide a list of label/value/count dicts. """ i1 = add_institution(name='Institution 1') i2 = add_institution(name='Institution 2') i3 = add_institution(name='Institution 3') for i in range(3): c = add_citation() Institution_Document.create(institution=i1, document=c.document) for i in range(2): c = add_citation() Institution_Document.create(institution=i2, document=c.document) for i in range(1): c = add_citation() Institution_Document.create(institution=i3, document=c.document) Citation_Index.es_insert() Institution_Index.es_insert() facets = institution_facets() assert facets == [ dict(label='Institution 1', value=i1.id, count=3), dict(label='Institution 2', value=i2.id, count=2), dict(label='Institution 3', value=i3.id, count=1), ]
def test_es_insert(es, add_institution): """ Institution_Index.es_insert() should index institutions. """ for i in range(10): add_institution('inst' + str(i)) Institution_Index.es_insert() for inst in Institution.select(): doc = config.es.get( index='institution', id=inst.id, ) assert doc['_source']['name'] == inst.name
def test_es_insert(es, add_institution): """ Institution_Index.es_insert() should index institutions. """ for i in range(10): add_institution('inst'+str(i)) Institution_Index.es_insert() for inst in Institution.select(): doc = config.es.get( index='institution', id=inst.id, ) assert doc['_source']['name'] == inst.name
def country_facets(): """ Materialize state facets with counts. Returns: dict: {label, value, count} """ counts = Citation_Index.count_facets('country') return Institution_Index.materialize_country_facets(counts)
def institution_facets(): """ Materialize institution facets with counts. Returns: dict: {label, value, count} """ counts = Citation_Index.count_facets('institution_id') return Institution_Index.materialize_institution_facets(counts)
def country_facets(): """ Materialize state facets with counts. Returns: dict: {label, value, count} """ counts = Citation_Index.count_facets("country") return Institution_Index.materialize_country_facets(counts)
def institution_facets(): """ Materialize institution facets with counts. Returns: dict: {label, value, count} """ counts = Citation_Index.count_facets("institution_id") return Institution_Index.materialize_institution_facets(counts)
def institution_facets(depth=200, include=None): """ Materialize institution facets with counts. Args: depth (int) include (list) Returns: dict: {label, value, count} """ counts = Citation_Index.count_facets( 'institution_id', depth=depth, include=include, ) return Institution_Index.materialize_institution_facets(counts)