def get_matching_activity_dicts(query_string, search_cursor): """Given a query string and a search cursor, returns a list of activity dicts that satisfy the search query. """ # We only populate collections in the initial load, since the current # frontend search infrastructure is set up to only deal with one search # cursor at a time. # TODO(sll): Remove this special casing. collection_ids = [] if not search_cursor: collection_ids, _ = ( collection_services.get_collection_ids_matching_query( query_string)) exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query( query_string, cursor=search_cursor)) activity_list = [] activity_list = ( summary_services.get_displayable_collection_summary_dicts_matching_ids( collection_ids)) activity_list += ( summary_services.get_displayable_exp_summary_dicts_matching_ids( exp_ids)) if len(activity_list) == feconf.DEFAULT_QUERY_LIMIT: logging.error( '%s activities were fetched to load the library page. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) return activity_list, new_search_cursor
def get_matching_activity_dicts(query_string, categories, language_codes, search_offset): """Given the details of a query and a search offset, returns a list of activity dicts that satisfy the query. Args: query_string: str. The search query string (this is what the user enters). categories: list(str). The list of categories to query for. If it is empty, no category filter is applied to the results. If it is not empty, then a result is considered valid if it matches at least one of these categories. language_codes: list(str). The list of language codes to query for. If it is empty, no language code filter is applied to the results. If it is not empty, then a result is considered valid if it matches at least one of these language codes. search_offset: int or None. Offset indicating where, in the list of exploration search results, to start the search from. If None, collection search results are returned first before the explorations. Returns: tuple. A tuple consisting of two elements: - list(dict). Each element in this list is a collection or exploration summary dict, representing a search result. - int. The exploration index offset from which to start the next search. """ # We only populate collections in the initial load, since the current # frontend search infrastructure is set up to only deal with one search # offset at a time. # TODO(sll): Remove this special casing. collection_ids = [] if not search_offset: collection_ids, _ = ( collection_services.get_collection_ids_matching_query( query_string, categories, language_codes)) exp_ids, new_search_offset = ( exp_services.get_exploration_ids_matching_query(query_string, categories, language_codes, offset=search_offset)) activity_list = ( summary_services.get_displayable_collection_summary_dicts_matching_ids( collection_ids) + summary_services.get_displayable_exp_summary_dicts_matching_ids( exp_ids)) if len(activity_list) == feconf.DEFAULT_QUERY_LIMIT: logging.exception( '%s activities were fetched to load the library page. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) return activity_list, new_search_offset
def get(self): """Handles GET requests.""" collection_ids = ( self.normalized_request.get('stringified_collection_ids')) summaries = ( summary_services.get_displayable_collection_summary_dicts_matching_ids( # pylint: disable=line-too-long collection_ids)) self.values.update({ 'summaries': summaries }) self.render_json(self.values)
def get(self): """Handles GET requests.""" try: collection_ids = json.loads( self.request.get('stringified_collection_ids')) except Exception: raise self.PageNotFoundException summaries = ( summary_services.get_displayable_collection_summary_dicts_matching_ids( # pylint: disable=line-too-long collection_ids)) self.values.update({ 'summaries': summaries }) self.render_json(self.values)
def get_matching_activity_dicts(query_string, search_cursor): """Given a query string and a search cursor, returns a list of activity dicts that satisfy the search query. """ collection_ids, search_cursor = ( collection_services.get_collection_ids_matching_query( query_string, cursor=search_cursor)) exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query(query_string, cursor=search_cursor)) activity_list = [] activity_list = ( summary_services.get_displayable_collection_summary_dicts_matching_ids( collection_ids)) activity_list += (summary_services. get_displayable_exp_summary_dicts_matching_ids(exp_ids)) if len(activity_list) == feconf.DEFAULT_QUERY_LIMIT: logging.error( '%s activities were fetched to load the library page. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) return activity_list, new_search_cursor
def get_matching_activity_dicts(query_string, search_cursor): """Given a query string and a search cursor, returns a list of activity dicts that satisfy the search query. """ collection_ids, search_cursor = ( collection_services.get_collection_ids_matching_query( query_string, cursor=search_cursor)) exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query( query_string, cursor=search_cursor)) activity_list = [] activity_list = ( summary_services.get_displayable_collection_summary_dicts_matching_ids( collection_ids)) activity_list += ( summary_services.get_displayable_exp_summary_dicts_matching_ids( exp_ids)) if len(activity_list) == feconf.DEFAULT_QUERY_LIMIT: logging.error( '%s activities were fetched to load the library page. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) return activity_list, new_search_cursor