@@ -243,17 +243,11 @@ def choose_candidate(rescored):
243243
244244def 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
311305def 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
327311def 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
0 commit comments