Skip to content

Commit

Permalink
records: implement collaborations name 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 29, 2017
1 parent 736f324 commit 6ba8ac1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion inspirehep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@
)),
book_title=dict(completion=dict(
field='bookautocomplete'
))
)),
collaboration_name=dict(completion=dict(
field='collaborations.collaboration_suggest'
))
),
list_route='/literature/',
item_route=(
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 @@ -310,6 +310,9 @@
},
"value": {
"type": "string"
},
"collaboration_suggest": {
"type": "completion"
}
},
"type": "object"
Expand Down
19 changes: 19 additions & 0 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_collaboration_suggest(sender, json, *args, **kwargs)
populate_abstract_source_suggest(sender, json, *args, **kwargs)
populate_affiliation_suggest(sender, json, *args, **kwargs)
populate_author_count(sender, json, *args, **kwargs)
Expand Down Expand Up @@ -184,6 +185,24 @@ def populate_bookautocomplete(sender, json, *args, **kwargs):
})


def populate_collaboration_suggest(sender, json, *args, **kwargs):
"""Populate the ```collaboration_suggest`` field of Literature records."""
if 'hep.json' not in json.get('$schema'):
return

collaborations = json.get('collaborations', [])

for collaboration in collaborations:
name = collaboration.get('value')
if name:
collaboration.update({
'collaboration_suggest': {
'input': name,
'output': name,
},
})


def populate_inspire_document_type(sender, json, *args, **kwargs):
"""Populate the ``facet_inspire_doc_type`` field of Literature records."""
if 'hep.json' not in json.get('$schema'):
Expand Down

0 comments on commit 6ba8ac1

Please sign in to comment.