Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions rorapi/common/matching_single_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,11 @@ def choose_candidate(rescored):

def match_by_query(text, query, countries):
"""Match affiliation text using specific ES query."""
try:
scored_candidates = []
chosen_candidate = None
chosen_true = None
results = query.execute()
except Exception as e:
return f"query error: {e}", None
try:
candidates = results.hits.hits
except Exception as e:
return f"candidates error: {e}\n{results}", None
scored_candidates = []
chosen_candidate = None
chosen_true = None
results = query.execute()
candidates = results.hits.hits
if candidates:
candidates = [c for c in candidates if c["_source"]["status"] == "active"]
scored_candidates = [score(text, c) for c in candidates]
Expand Down Expand Up @@ -310,25 +304,13 @@ def get_output(chosen, all_matched, active_only):

def get_candidates(aff, countries, version):
qb = ESQueryBuilder(version)
try:
# get the index mappings for an index
curr_v2_index = ES7.indices.get_mapping('organizations-v2')
# return as json string
return json.dumps(curr_v2_index), None
except Exception as e:
return f"query error {version}: {e}", None
try:
qb.add_affiliation_query(aff, 200)
return match_by_query(aff, qb.get_query(), countries)
except Exception as e:
return f"query error: {e}", None
qb.add_affiliation_query(aff, 200)
return match_by_query(aff, qb.get_query(), countries)


def match_affiliation(affiliation, active_only, version):
countries = get_countries(affiliation)
chosen, all_matched = get_candidates(affiliation, countries, version)
if isinstance(chosen, str):
return chosen
return get_output(chosen, all_matched, active_only)


Expand Down
4 changes: 0 additions & 4 deletions rorapi/management/commands/indexror.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ def index(dataset, version):
'id': n
} for n in get_nested_ids_v1(org)]
body.append(org)
print("example_1: ", body[0])
print("example_1: ", body[1])
print("example_2: ", body[8])
print("example_2: ", body[9])
ES7.bulk(body)
except TransportError:
err[index.__name__] = f"Indexing error, reverted index back to previous state"
Expand Down
4 changes: 0 additions & 4 deletions rorapi/management/commands/indexrordump.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ def index_dump(self, filename, index, dataset):
'id': n
} for n in get_nested_ids_v1(org)]
body.append(org)
print("example_1: ", body[0])
print("example_1: ", body[1])
print("example_2: ", body[8])
print("example_2: ", body[9])
ES7.bulk(body)
except TransportError:
self.stdout.write(TransportError)
Expand Down