def show_results(n_clicks, dropdown_value, search_text): if n_clicks in [None, 0]: return "" else: try: if not search_text: return no_query_warning_html() try: entity_query, raw_text = parse_search_box(search_text) except MatscholarWebSearchError: return malformed_query_warning_html(search_text) if dropdown_value == 'abstracts': results = abstracts_results_html(entity_query, raw_text) elif dropdown_value == 'materials': results = materials_results_html(entity_query, raw_text) elif dropdown_value == 'entities': results = entities_results_html(entity_query, raw_text) elif dropdown_value == 'everything': results = everything_results_html(entity_query, raw_text) else: raise ValueError( f"Dropdown selection {dropdown_value} not valid!" ) return results except MatScholarRestError: rester_error = default_message return common_rester_error_html(rester_error)
def show_search_results(go_button_n_clicks, dropdown_value, search_text): """ Determine what kind of results to show from the search text, search type, and number of clicks of the search button. Args: go_button_n_clicks (int): The number of clicks of the "Go" button. dropdown_value (str): The type of search to execute. search_text (str): The raw search text as entered in the search field. Returns: (dash_html_components.Div): The correct html block for the search type and customized according to search results from the search text. """ if go_button_n_clicks in [None, 0]: return "" else: try: if not search_text: return no_query_warning_html() try: entity_query, raw_text = parse_search_box(search_text) except MatscholarWebSearchError: return malformed_query_warning_html(search_text) if dropdown_value == "abstracts": results = abstracts_results_html(entity_query, raw_text) elif dropdown_value == "materials": results = materials_results_html(entity_query, raw_text) elif dropdown_value == "entities": results = entities_results_html(entity_query, raw_text) elif dropdown_value == "everything": results = everything_results_html(entity_query, raw_text) else: raise ValueError( f"Dropdown selection {dropdown_value} not valid!") if is_cobalt_search(entity_query, raw_text): results = cobalt_warning_html(results) return results except MatScholarRestError: rester_error = ( "Our database had trouble with that query. We are likely " "undergoing maintenance, please visit again later!") return common_rester_error_html(rester_error)