diff --git a/rero_ils/modules/documents/listener.py b/rero_ils/modules/documents/listener.py index 74bd147dd0..f119ea1b4d 100644 --- a/rero_ils/modules/documents/listener.py +++ b/rero_ils/modules/documents/listener.py @@ -17,6 +17,8 @@ """Signals connector for Document.""" +from isbnlib import is_isbn10, is_isbn13, to_isbn10, to_isbn13 + from .utils import create_contributions, title_format_text_head from ..documents.api import Document, DocumentsSearch from ..holdings.api import Holding, HoldingsSearch @@ -156,3 +158,23 @@ def enrich_document_data(sender, json=None, record=None, index=None, 'doc', document_pid) if local_fields: json['local_fields'] = local_fields + # index both ISBN 10 and 13 format + + def filter_isbn(identified_by): + """Filter identified_by for type bf:Isbn.""" + return identified_by.get('type') == 'bf:Isbn' + + filtered_identified_by = filter( + filter_isbn, + json.get('identifiedBy', []) + ) + isbns = set() + for identified_by in filtered_identified_by: + isbn = identified_by['value'] + isbns.add(isbn) + if is_isbn10(isbn): + isbns.add(to_isbn13(isbn)) + elif is_isbn13(isbn): + isbns.add(to_isbn10(isbn)) + if isbns: + json['isbn'] = list(isbns) diff --git a/rero_ils/modules/documents/mappings/v7/documents/document-v0.0.1.json b/rero_ils/modules/documents/mappings/v7/documents/document-v0.0.1.json index 2f5035829e..6f97a4aad3 100644 --- a/rero_ils/modules/documents/mappings/v7/documents/document-v0.0.1.json +++ b/rero_ils/modules/documents/mappings/v7/documents/document-v0.0.1.json @@ -919,6 +919,9 @@ "harvested": { "type": "boolean" }, + "isbn": { + "type": "keyword" + }, "_draft": { "type": "boolean" }, diff --git a/tests/api/test_external_services.py b/tests/api/test_external_services.py index 1b2b23a0ab..ede6c97d0e 100644 --- a/tests/api/test_external_services.py +++ b/tests/api/test_external_services.py @@ -47,6 +47,7 @@ def clean_authorized_access_point(data): contributions.append(contribution) data.pop('sort_title', None) + data.pop('isbn', None) return data item_url = url_for('invenio_records_rest.doc_item', pid_value='doc1') diff --git a/tests/ui/documents/test_documents_mapping.py b/tests/ui/documents/test_documents_mapping.py index 46613532ee..63428abddf 100644 --- a/tests/ui/documents/test_documents_mapping.py +++ b/tests/ui/documents/test_documents_mapping.py @@ -51,30 +51,36 @@ 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 + count = search.query('query_string', query='reine Berthe').count() + assert count == 2 - c = search.query('query_string', query='maison').count() - assert c == 1 + count = search.query('query_string', query='maison').count() + assert count == 1 - c = search.query('query_string', query='scene').count() - assert c == 1 + count = search.query('query_string', query='scene').count() + assert count == 1 query = MultiMatch(query='scène', fields=['abstracts.fre']) - c = search.query(query).count() - assert c == 1 + count = search.query(query).count() + assert count == 1 - c = search.query('query_string', query='Körper').count() - assert c == 1 + count = search.query('query_string', query='Körper').count() + assert count == 1 query = MultiMatch(query='Körper', fields=['abstracts.ger']) - c = search.query(query).count() - assert c == 1 + count = search.query(query).count() + assert count == 1 - c = search.query('query_string', query='Chamber Secrets').count() - assert c == 1 + count = search.query('query_string', query='Chamber Secrets').count() + assert count == 1 query = MultiMatch(query='Chamber of Secrets', fields=['title._text.*']) - c = search.query(query).count() - assert c == 1 + 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