コード例 #1
0
def test_document_search_mapping(app, document_records):
    """Test document search mapping."""
    search = DocumentsSearch()

    c = search.query('query_string', query='reine Berthe').count()
    assert c == 2

    c = search.query('query_string', query='maison').count()
    assert c == 1

    c = search.query('query_string', query='scene').count()
    assert c == 1

    query = MultiMatch(query='scène', fields=['abstracts.fre'])
    c = search.query(query).count()
    assert c == 1

    c = search.query('query_string', query='Körper').count()
    assert c == 1

    query = MultiMatch(query='Körper', fields=['abstracts.ger'])
    c = search.query(query).count()
    assert c == 1

    c = search.query('query_string', query='Chamber Secrets').count()
    assert c == 1

    query = MultiMatch(query='Chamber of Secrets', fields=['title.eng'])
    c = search.query(query).count()
    assert c == 1
コード例 #2
0
def test_replace_idby_subjects(mock_contributions_mef_get, app, document_data,
                               contribution_person_response_data):
    """Test replace identifiedBy in subjects."""
    assert replace_idby_subjects() == (0, 0, 0, 0, 0)

    doc = Document.create(data=document_data, dbcommit=True, reindex=True)
    DocumentsSearch.flush_and_refresh()
    replace = ReplaceMefIdentifiedBySubjects()
    replace.process()
    assert replace.counts_len == (0, 0, 0, 0, 1)

    without_idref_gnd = deepcopy(contribution_person_response_data)
    without_idref_gnd['hits']['hits'][0]['metadata'].pop('idref')
    without_idref_gnd['hits']['hits'][0]['metadata'].pop('gnd')
    mock_contributions_mef_get.return_value = mock_response(
        json_data=without_idref_gnd)
    assert replace_idby_subjects() == (0, 0, 0, 1, 0)

    without_idref_gnd = deepcopy(contribution_person_response_data)
    without_idref_gnd['hits']['hits'][0]['metadata']['deleted'] = '2022'
    mock_contributions_mef_get.return_value = mock_response(
        json_data=without_idref_gnd)
    assert replace_idby_subjects() == (0, 0, 1, 0, 0)

    mock_contributions_mef_get.return_value = mock_response(
        json_data=contribution_person_response_data)
    assert replace_idby_subjects() == (1, 0, 0, 0, 0)

    # clean up
    doc.delete(dbcommit=True, delindex=True, force=True)
    for id in Contribution.get_all_ids():
        cont = Contribution.get_record_by_id(id)
        cont.delete(dbcommit=True, delindex=True, force=True)
コード例 #3
0
def test_document_search_mapping(app, document_records):
    """Test document search mapping."""
    search = DocumentsSearch()

    count = search.query('query_string', query='reine Berthe').count()
    assert count == 2

    count = search.query('query_string', query='maison').count()
    assert count == 1

    count = search.query('query_string', query='Körper').count()
    assert count == 1

    count = search.query('query_string', query='Chamber Secrets').count()
    assert count == 1

    query = MultiMatch(query='Chamber of Secrets', fields=['title._text.*'])
    count = search.query(query).count()
    assert count == 1

    count = search.query('query_string', query='9782823855890').count()
    assert count == 1

    count = search.query('query_string', query='2823855890').count()
    assert count == 1
コード例 #4
0
def test_local_fields_es_mapping(db, org_sion, document,
                                 local_field_sion_data):
    """Test local fields elasticsearch mapping."""
    search = LocalFieldsSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    lofi = LocalField.create(local_field_sion_data,
                             dbcommit=True,
                             reindex=True,
                             delete_pid=True)
    flush_index(LocalFieldsSearch.Meta.index)
    assert mapping == get_mapping(search.Meta.index)

    assert lofi == local_field_sion_data
    assert lofi.get('pid') == '1'

    lofi = LocalField.get_record_by_pid('1')
    assert lofi == local_field_sion_data

    fetched_pid = fetcher(lofi.id, lofi)
    assert fetched_pid.pid_value == '1'
    assert fetched_pid.pid_type == 'lofi'

    document_pid = extracted_data_from_ref(lofi.get('parent'))
    search = DocumentsSearch().filter('term', pid=document_pid)
    document = list(search.scan())[0].to_dict()
    for field in document['local_fields']:
        if field['organisation_pid'] == document_pid:
            assert field['fields'] ==\
                local_field_sion_data['fields']['field_1']
コード例 #5
0
            def get_documents_by_item_pids(item_pids):
                """Get documents for the given item pid list."""
                def _build_doc(data):
                    document_data = {
                        'document_title':
                        next(
                            filter(lambda x: x.get('type') == 'bf:Title',
                                   data.get('title'))).get('_text')
                    }
                    # process contributions
                    creator = []
                    if 'contribution' in data:
                        for contribution in data.get('contribution'):
                            if any(role in contribution.get('role')
                                   for role in role_filter):
                                authorized_access_point = \
                                    f'authorized_access_point_{language}'
                                if authorized_access_point in contribution\
                                        .get('agent'):
                                    creator.append(contribution['agent']
                                                   [authorized_access_point])
                    document_data['document_creator'] = ' ; '.join(creator)
                    document_main_type = []
                    document_sub_type = []
                    for document_type in data.get('type'):
                        # data = document_type.to_dict()
                        document_main_type.append(
                            document_type.get('main_type'))
                        document_sub_type.append(
                            document_type.get('subtype', ''))
                    document_data['document_main_type'] = ', '.join(
                        document_main_type)
                    document_data['document_sub_type'] = ', '.join(
                        document_sub_type)
                    # TODO : build provision activity
                    return document_data

                doc_search = DocumentsSearch() \
                    .filter('terms', holdings__items__pid=list(item_pids)) \
                    .source(
                    ['pid', 'title', 'contribution', 'provisionActivity',
                     'type'])
                docs = {}
                for doc in doc_search.scan():
                    docs[doc.pid] = _build_doc(doc.to_dict())
                return docs
コード例 #6
0
def test_document_es_mapping(es, db, org_martigny, document_data_ref,
                             item_lib_martigny, person):
    """Test document elasticsearch mapping."""
    search = DocumentsSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    data = deepcopy(document_data_ref)
    Document.create(data, dbcommit=True, reindex=True, delete_pid=True)
    assert mapping == get_mapping(search.Meta.index)
コード例 #7
0
def test_document_es_mapping(db, org_martigny, document_data_tmp,
                             item_lib_martigny):
    """Test document elasticsearch mapping."""
    search = DocumentsSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    Document.create(document_data_tmp,
                    dbcommit=True,
                    reindex=True,
                    delete_pid=True)
    assert mapping == get_mapping(search.Meta.index)
コード例 #8
0
def test_document_es_mapping(es_clear, db, organisation, document_data_tmp,
                             item_on_loan):
    """."""
    search = DocumentsSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    Document.create(document_data_tmp,
                    dbcommit=True,
                    reindex=True,
                    delete_pid=True)
    assert mapping == get_mapping(search.Meta.index)
コード例 #9
0
def test_document_es_mapping(mock_contributions_mef_get, es, db, org_martigny,
                             document_data_ref, item_lib_martigny,
                             contribution_person_response_data):
    """Test document elasticsearch mapping."""
    search = DocumentsSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    data = deepcopy(document_data_ref)
    mock_contributions_mef_get.return_value = mock_response(
        json_data=contribution_person_response_data)
    Document.create(data, dbcommit=True, reindex=True, delete_pid=True)
    assert mapping == get_mapping(search.Meta.index)