|
3 | 3 | import json |
4 | 4 | import os |
5 | 5 | import sys |
6 | | -from collections import Counter |
| 6 | + |
7 | 7 | from senzing import ( |
8 | 8 | G2BadInputException, |
9 | 9 | G2Engine, |
| 10 | + G2EngineFlags, |
10 | 11 | G2Exception, |
11 | 12 | G2RetryableException, |
12 | 13 | G2UnrecoverableException, |
@@ -42,59 +43,30 @@ def mock_logger(level, exception, error_rec=None): |
42 | 43 | def searcher(engine): |
43 | 44 | for rec_to_search in search_records: |
44 | 45 | try: |
| 46 | + rec_str = json.dumps(rec_to_search) |
45 | 47 | search_response = bytearray() |
46 | | - engine.searchByAttributes(json.dumps(rec_to_search), search_response) |
| 48 | + engine.searchByAttributes( |
| 49 | + rec_str, |
| 50 | + search_response, |
| 51 | + G2EngineFlags.G2_SEARCH_BY_ATTRIBUTES_MINIMAL_ALL, |
| 52 | + ) |
47 | 53 | except (G2BadInputException, json.JSONDecodeError) as err: |
48 | | - mock_logger("ERROR", err, rec_to_search) |
| 54 | + mock_logger("ERROR", err, rec_str) |
49 | 55 | except G2RetryableException as err: |
50 | | - mock_logger("WARN", err, rec_to_search) |
| 56 | + mock_logger("WARN", err, rec_str) |
51 | 57 | except (G2UnrecoverableException, G2Exception) as err: |
52 | | - mock_logger("CRITICAL", err, rec_to_search) |
| 58 | + mock_logger("CRITICAL", err, rec_str) |
53 | 59 | raise |
54 | 60 | else: |
55 | | - response_dict = json.loads(search_response.decode()) |
| 61 | + response_str = search_response.decode() |
| 62 | + response_dict = json.loads(response_str) |
56 | 63 | response_entities = response_dict.get("RESOLVED_ENTITIES", None) |
57 | 64 |
|
| 65 | + print("-" * 100) |
58 | 66 | if response_entities: |
59 | | - results_str = [] |
60 | | - results_count = Counter( |
61 | | - k |
62 | | - for entity in response_entities |
63 | | - for k in entity.keys() |
64 | | - if k.startswith("MATCH_INFO") |
65 | | - ) |
66 | | - results_str.append( |
67 | | - f'\n{results_count["MATCH_INFO"]} results for' |
68 | | - f" {json.dumps(rec_to_search)}\n" |
69 | | - ) |
70 | | - |
71 | | - for idx, result in enumerate(response_entities, start=1): |
72 | | - results_str.append(f"\n Result {idx}") |
73 | | - results_str.append( |
74 | | - "\n Entity ID: " |
75 | | - f" {result['ENTITY']['RESOLVED_ENTITY']['ENTITY_ID']}" |
76 | | - ) |
77 | | - results_str.append( |
78 | | - "\n Entity name: " |
79 | | - f" {result['ENTITY']['RESOLVED_ENTITY']['ENTITY_NAME']}" |
80 | | - ) |
81 | | - results_str.append( |
82 | | - f'\n Match key: {result["MATCH_INFO"]["MATCH_KEY"]}' |
83 | | - ) |
84 | | - results_str.append("\n Records summary: ") |
85 | | - for record_summary in result["ENTITY"]["RESOLVED_ENTITY"][ |
86 | | - "RECORD_SUMMARY" |
87 | | - ]: |
88 | | - results_str.append( |
89 | | - f'{record_summary["DATA_SOURCE"]}:' |
90 | | - f' {record_summary["RECORD_COUNT"]}' |
91 | | - + " " |
92 | | - ) |
93 | | - results_str.append("\n") |
94 | | - |
95 | | - print("".join(results_str)) |
| 67 | + print(f"Result for {rec_str}:\n\n{response_str}\n") |
96 | 68 | else: |
97 | | - print(f"\nNo result for {json.dumps(rec_to_search)}\n") |
| 69 | + print(f"No result for {rec_str}\n") |
98 | 70 |
|
99 | 71 |
|
100 | 72 | try: |
|
0 commit comments