Skip to content

Commit

Permalink
es: index both ISBN 10 and 13 format
Browse files Browse the repository at this point in the history
* closes: rero#1486

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed Feb 1, 2021
1 parent 45722af commit a274c00
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
21 changes: 21 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,22 @@ 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))
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
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 a274c00

Please sign in to comment.