From 6f087d08f4a0806e634b32ab89b8fcde270ca94e Mon Sep 17 00:00:00 2001 From: Iuliana Voinea Date: Tue, 28 Nov 2017 17:21:26 +0100 Subject: [PATCH] records: implement book_series title autocomplete Signed-off-by: Iuliana Voinea --- inspirehep/config.py | 7 +++-- .../modules/records/mappings/records/hep.json | 3 +++ inspirehep/modules/records/receivers.py | 27 +++++++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/inspirehep/config.py b/inspirehep/config.py index a9ef948ca0..d5c48742aa 100644 --- a/inspirehep/config.py +++ b/inspirehep/config.py @@ -367,9 +367,12 @@ book_title=dict(completion=dict( field='bookautocomplete' )), + book_series=dict(completion=dict( + field='book_series.book_series_suggest' + )), collaboration_name=dict(completion=dict( - field='collaborations.collaboration_suggest' - )) + field='collaborations.collaboration_suggest' + )) ), list_route='/literature/', item_route=( diff --git a/inspirehep/modules/records/mappings/records/hep.json b/inspirehep/modules/records/mappings/records/hep.json index 62fe626fb2..be945bc74b 100644 --- a/inspirehep/modules/records/mappings/records/hep.json +++ b/inspirehep/modules/records/mappings/records/hep.json @@ -281,6 +281,9 @@ }, "volume": { "type": "string" + }, + "book_series_suggest": { + "type": "completion" } }, "type": "object" diff --git a/inspirehep/modules/records/receivers.py b/inspirehep/modules/records/receivers.py index 79f59b4afb..a97a3ce8e8 100644 --- a/inspirehep/modules/records/receivers.py +++ b/inspirehep/modules/records/receivers.py @@ -138,6 +138,7 @@ def enhance_after_index(sender, json, *args, **kwargs): """ populate_recid_from_ref(sender, json, *args, **kwargs) populate_bookautocomplete(sender, json, *args, **kwargs) + populate_book_series_suggest(sender, json, *args, **kwargs) populate_collaboration_suggest(sender, json, *args, **kwargs) populate_abstract_source_suggest(sender, json, *args, **kwargs) populate_affiliation_suggest(sender, json, *args, **kwargs) @@ -149,7 +150,7 @@ def enhance_after_index(sender, json, *args, **kwargs): def populate_bookautocomplete(sender, json, *args, **kwargs): - """Populate the ```bookautocomplete`` field of Literature records.""" + """Populate the ``bookautocomplete`` field of Literature records.""" if 'hep.json' not in json.get('$schema'): return @@ -185,8 +186,30 @@ def populate_bookautocomplete(sender, json, *args, **kwargs): }) +def populate_book_series_suggest(sender, json, *args, **kwargs): + """Populate the ``book_series_suggest`` field of Literature records.""" + if 'hep.json' not in json.get('$schema'): + return + + doc_types = json.get('document_type', []) + if all(doc_type not in doc_types for doc_type in ['book', 'thesis', 'proceedings']): + return + + book_series = json.get('book_series', []) + + for series in book_series: + title = series.get('title') + if title: + series.update({ + 'book_series_suggest': { + 'input': title, + 'output': title + }, + }) + + def populate_collaboration_suggest(sender, json, *args, **kwargs): - """Populate the ```collaboration_suggest`` field of Literature records.""" + """Populate the ``collaboration_suggest`` field of Literature records.""" if 'hep.json' not in json.get('$schema'): return