def find_match_fields(result: R, possible_regex_list=None): """ Get list of matched fields inside the searchresult Args: result: Generic search result possible_regex_list: list of text regex from the pipeline builder Returns: list of fields where the regex matched """ matched_fields = [] fields = result.fields if not possible_regex_list: return None for regex_ in possible_regex_list: try: runtime_regex = Regex(regex_, 'imsx').try_compile() except Exception: runtime_regex = regex_ for field in fields: try: res = runtime_regex.findall(str(field.get('value'))) if len(res) > 0: matched_fields.append(field) except Exception: continue if len(matched_fields) > 0: return matched_fields return None
def inner_match_fields(_fields, _matched_fields, _reference=None): """ Get list of matched fields inside the reference fields Args: _fields: list of referenced fields _matched_fields: list of text regex from the pipeline builder _reference: reference object to which the reference field refers Returns: list of fields where the regex matched """ for regex_ in possible_regex_list: try: runtime_regex = Regex(regex_, 'ims').try_compile() except Exception: runtime_regex = regex_ for field in _fields: try: res = runtime_regex.findall(str(field.get('value'))) if len(res) > 0: inner_value = _reference if _reference else field # removing duplicated from list if inner_value not in _matched_fields: _matched_fields.append(inner_value) if field['type'] == 'ref': inner_match_fields(field['reference']['summaries'], _matched_fields, field) if field['type'] == 'ref-section-field': inner_match_fields(field['references']['fields'], _matched_fields, field) except Exception: continue