Skip to content

Commit

Permalink
records: implement book_series title autocomplete
Browse files Browse the repository at this point in the history
Signed-off-by: Iuliana Voinea <[email protected]>
  • Loading branch information
Iuliana Voinea committed Nov 28, 2017
1 parent a9f84e4 commit 0eab17c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions inspirehep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@
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'
))
Expand Down
3 changes: 3 additions & 0 deletions inspirehep/modules/records/mappings/records/hep.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@
},
"volume": {
"type": "string"
},
"book_series_suggest": {
"type": "completion"
}
},
"type": "object"
Expand Down
27 changes: 25 additions & 2 deletions inspirehep/modules/records/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0eab17c

Please sign in to comment.