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(self): """Handles GET requests.""" # TODO(sll): Figure out what to do about explorations in categories # other than those explicitly listed. query_string = self.request.get('q') search_cursor = self.request.get('cursor', None) exp_ids, search_cursor = ( exp_services.get_exploration_ids_matching_query( query_string, cursor=search_cursor)) explorations_list = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( exp_ids)) if len(explorations_list) == feconf.DEFAULT_QUERY_LIMIT: logging.error( '%s explorations were fetched to load the gallery page. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) preferred_language_codes = [feconf.DEFAULT_LANGUAGE_CODE] if self.user_id: user_settings = user_services.get_user_settings(self.user_id) preferred_language_codes = user_settings.preferred_language_codes self.values.update({ 'explorations_list': explorations_list, 'preferred_language_codes': preferred_language_codes, 'search_cursor': search_cursor, }) self.render_json(self.values)
def get_exp_metadata_dicts_matching_query(query_string, search_cursor, user): """Given a query string and a search cursor, returns a list of exploration metadata dicts that satisfy the search query. Args: query_string: str. The search query for which the search is to be performed. search_cursor: str or None. The cursor location to start the search from. If None, the returned values are from the beginning of the results list. user: UserActionsInfo. Object having user_id, role and actions for given user. Returns: 2-tuple of (exploration_list, new_search_cursor). Where: - exploration_list list(dict). A list of metadata dicts for explorations matching the query. - new_search_cursor (str). New search cursor location. """ exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query(query_string, cursor=search_cursor)) exploration_list = get_exploration_metadata_dicts(exp_ids, user) return exploration_list, new_search_cursor
def get_exp_metadata_dicts_matching_query(query_string, search_cursor, user_id): """Given a query string and a search cursor, returns a list of exploration metadata dicts that satisfy the search query. Args: query_string: str. The search query for which the search is to be performed. search_cursor: str or None. The cursor location to start the search from. If None, the returned values are from the beginning of the results list. user_id: str or None. If not None, private explorations that are editable by this user are also returned. Returns: exploration_list: A list of metadata dicts for explorations matching the query. new_search_cursor: New search cursor location. """ exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query(query_string, cursor=search_cursor)) exploration_list = get_exploration_metadata_dicts(exp_ids, user_id) return exploration_list, new_search_cursor
def get_exp_metadata_dicts_matching_query(query_string, search_cursor, user_id): """Given a query string and a search cursor, returns a list of exploration metadata dicts that satisfy the search query. Args: query_string: str. The search query for which the search is to be performed. search_cursor: str or None. The cursor location to start the search from. If None, the returned values are from the beginning of the results list. user_id: str or None. If not None, private explorations that are editable by this user are also returned. Returns: exploration_list: A list of metadata dicts for explorations matching the query. new_search_cursor: New search cursor location. """ exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query( query_string, cursor=search_cursor)) exploration_list = get_exploration_metadata_dicts(exp_ids, user_id) return exploration_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_matching_exploration_dicts(query_string, search_cursor): """Given a query string and a search cursor, returns a list of exploration dicts that satisfy the search query. """ exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query( query_string, cursor=search_cursor)) explorations_list = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( exp_ids)) if len(explorations_list) == feconf.DEFAULT_QUERY_LIMIT: logging.error( '%s explorations were fetched to load the search results. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) return explorations_list, new_search_cursor
def get_matching_exploration_dicts(query_string, search_cursor): """Given a query string and a search cursor, returns a list of exploration dicts that satisfy the search query. """ exp_ids, new_search_cursor = ( exp_services.get_exploration_ids_matching_query(query_string, cursor=search_cursor)) explorations_list = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( exp_ids)) if len(explorations_list) == feconf.DEFAULT_QUERY_LIMIT: logging.error( '%s explorations were fetched to load the search results. ' 'You may be running up against the default query limits.' % feconf.DEFAULT_QUERY_LIMIT) return explorations_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
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