Skip to content

Commit

Permalink
search: indexes ISBN 10 and 13 format
Browse files Browse the repository at this point in the history
* Closes #1486.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
2 people authored and iGor milhit committed Feb 4, 2021
1 parent e1d40b4 commit ed60b4c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
22 changes: 22 additions & 0 deletions rero_ils/modules/documents/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@
"harvested": {
"type": "boolean"
},
"isbn": {
"type": "keyword"
},
"_draft": {
"type": "boolean"
},
Expand Down
1 change: 1 addition & 0 deletions tests/api/test_external_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
38 changes: 22 additions & 16 deletions tests/ui/documents/test_documents_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ed60b4c

Please sign in to comment.