def generic_listing_searchable_text(instance, catalog_name, exclude_field_names=None, include_field_names=None): """Retrieves all the values of metadata columns in the catalog for wildcard searches :param instance: the object to retrieve metadata/values from :param catalog_name: the catalog to retrieve metadata from :param exclude_field_names: field names to exclude from the metadata :param include_field_names: field names to include, even if no metadata """ entries = set() # Fields to include/exclude include = include_field_names or [] exclude = exclude_field_names or [] # Get the metadata fields from this instance and catalog catalog = api.get_tool(catalog_name) metadata = get_metadata_for(instance, catalog) for key, brain_value in metadata.items(): if key in exclude: continue elif key in include: # A metadata field already include.remove(key) instance_value = api.safe_getattr(instance, key, None) parsed = api.to_searchable_text_metadata(brain_value or instance_value) entries.add(parsed) # Include values from additional fields for field_name in include: field_value = api.safe_getattr(instance, field_name, None) field_value = api.to_searchable_text_metadata(field_value) entries.add(field_value) # Remove empties entries = filter(None, entries) # Concatenate all strings to one text blob return " ".join(entries)
def searchable_text(instance): """ Retrieves all the values of metadata columns in the catalog for wildcard searches :return: all metadata values joined in a string """ entries = [] catalog = api.get_tool(CATALOG_PATIENTS) columns = catalog.schema() brains = catalog({"UID": api.get_uid(instance)}) brain = brains[0] if brains else None for column in columns: brain_value = api.safe_getattr(brain, column, None) instance_value = api.safe_getattr(instance, column, None) parsed = api.to_searchable_text_metadata(brain_value or instance_value) entries.append(parsed) # Concatenate all strings to one text blob return " ".join(entries)
def searchable_text(instance): """ Retrieves all the values of metadata columns in the catalog for wildcard searches :return: all metadata values joined in a string """ entries = [] catalog = api.get_tool(CATALOG_PATIENTS) columns = catalog.schema() brains = catalog({"UID": api.get_uid(instance)}) brain = brains[0] if brains else None for column in columns: brain_value = api.safe_getattr(brain, column, None) instance_value = api.safe_getattr(instance, column, None) parsed = api.to_searchable_text_metadata(brain_value or instance_value) entries.append(parsed) # Concatenate all strings to one text blob return " ".join(entries)
def listing_searchable_text(instance): """ Retrieves all the values of metadata columns in the catalog for wildcard searches :return: all metadata values joined in a string """ entries = set() catalog = api.get_tool(CATALOG_ANALYSIS_REQUEST_LISTING) metadata = get_metadata_for(instance, catalog) for key, brain_value in metadata.items(): instance_value = api.safe_getattr(instance, key, None) parsed = api.to_searchable_text_metadata(brain_value or instance_value) entries.add(parsed) # add metadata of all descendants for descendant in instance.getDescendants(): entries.add(listing_searchable_text(descendant)()) # Concatenate all strings to one text blob return " ".join(entries)
def listing_searchable_text(instance): """ Retrieves all the values of metadata columns in the catalog for wildcard searches :return: all metadata values joined in a string """ entries = set() catalog = api.get_tool(CATALOG_ANALYSIS_REQUEST_LISTING) columns = catalog.schema() brains = catalog({"UID": api.get_uid(instance)}) brain = brains[0] if brains else None for column in columns: brain_value = api.safe_getattr(brain, column, None) instance_value = api.safe_getattr(instance, column, None) parsed = api.to_searchable_text_metadata(brain_value or instance_value) entries.add(parsed) # add metadata of all descendants for descendant in instance.getDescendants(): entries.add(listing_searchable_text(descendant)()) # Concatenate all strings to one text blob return " ".join(entries)
def get_value(instance, func_name): value = api.safe_getattr(instance, func_name, None) if not value: return None parsed = api.to_searchable_text_metadata(value) return parsed or None