Skip to content

Commit 6c7285f

Browse files
authored
Merge pull request #476 from ror-community/single-search-marple-implementation
Adding single search
2 parents 6c10d5c + e8cf6f5 commit 6c7285f

File tree

3 files changed

+7
-33
lines changed

3 files changed

+7
-33
lines changed

rorapi/common/matching_single_search.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,11 @@ def choose_candidate(rescored):
243243

244244
def match_by_query(text, query, countries):
245245
"""Match affiliation text using specific ES query."""
246-
try:
247-
scored_candidates = []
248-
chosen_candidate = None
249-
chosen_true = None
250-
results = query.execute()
251-
except Exception as e:
252-
return f"query error: {e}", None
253-
try:
254-
candidates = results.hits.hits
255-
except Exception as e:
256-
return f"candidates error: {e}\n{results}", None
246+
scored_candidates = []
247+
chosen_candidate = None
248+
chosen_true = None
249+
results = query.execute()
250+
candidates = results.hits.hits
257251
if candidates:
258252
candidates = [c for c in candidates if c["_source"]["status"] == "active"]
259253
scored_candidates = [score(text, c) for c in candidates]
@@ -310,25 +304,13 @@ def get_output(chosen, all_matched, active_only):
310304

311305
def get_candidates(aff, countries, version):
312306
qb = ESQueryBuilder(version)
313-
try:
314-
# get the index mappings for an index
315-
curr_v2_index = ES7.indices.get_mapping('organizations-v2')
316-
# return as json string
317-
return json.dumps(curr_v2_index), None
318-
except Exception as e:
319-
return f"query error {version}: {e}", None
320-
try:
321-
qb.add_affiliation_query(aff, 200)
322-
return match_by_query(aff, qb.get_query(), countries)
323-
except Exception as e:
324-
return f"query error: {e}", None
307+
qb.add_affiliation_query(aff, 200)
308+
return match_by_query(aff, qb.get_query(), countries)
325309

326310

327311
def match_affiliation(affiliation, active_only, version):
328312
countries = get_countries(affiliation)
329313
chosen, all_matched = get_candidates(affiliation, countries, version)
330-
if isinstance(chosen, str):
331-
return chosen
332314
return get_output(chosen, all_matched, active_only)
333315

334316

rorapi/management/commands/indexror.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ def index(dataset, version):
191191
'id': n
192192
} for n in get_nested_ids_v1(org)]
193193
body.append(org)
194-
print("example_1: ", body[0])
195-
print("example_1: ", body[1])
196-
print("example_2: ", body[8])
197-
print("example_2: ", body[9])
198194
ES7.bulk(body)
199195
except TransportError:
200196
err[index.__name__] = f"Indexing error, reverted index back to previous state"

rorapi/management/commands/indexrordump.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ def index_dump(self, filename, index, dataset):
9898
'id': n
9999
} for n in get_nested_ids_v1(org)]
100100
body.append(org)
101-
print("example_1: ", body[0])
102-
print("example_1: ", body[1])
103-
print("example_2: ", body[8])
104-
print("example_2: ", body[9])
105101
ES7.bulk(body)
106102
except TransportError:
107103
self.stdout.write(TransportError)

0 commit comments

Comments
 (0)