Skip to content

Commit

Permalink
unique DOIs in the SOLR document (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaccomazzi authored Aug 11, 2022
1 parent 369b1ed commit 047429d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion aip/classic/solr_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _doctype_facet_hier(ADS_record):
@staticmethod
def _doi(ADS_record):
result = [i['content'] for i in ADS_record['metadata']['general'].get('doi', [])]
return {'doi': result}
return {'doi': case_insensitive_unique_list(result)}

@staticmethod
def _eid(ADS_record):
Expand Down Expand Up @@ -580,6 +580,17 @@ def validate(cls, solr_record):
assert len(set([type(i) for i in v])) == 1, "{0}: multiple data-types in list: {1}".format(k, v)
assert isinstance(v[0], type(SCHEMA[k][0])), "{0}: inner list element has unexpected type ({1}!={2}): {3}".format(k, type(v[0]), type(SCHEMA[k][0]), v)

def case_insensitive_unique_list(array):
"""
Returns the list of unique elements in the input array
in a case-insensitive way, preserving order and case
"""
seen, result = set(), []
for item in array:
if item.lower() not in seen:
seen.add(item.lower())
result.append(item)
return result

def unroll_unique_list(array):
"""
Expand Down

0 comments on commit 047429d

Please sign in to comment.