def interpret_wsearch(query): """ Input: specification of a worksheet search query. Output: worksheet items based on the result of issuing the search query. """ # Get the worksheet uuids worksheet_infos = search_worksheets(query['keywords']) items = [subworksheet_item(worksheet_info) for worksheet_info in worksheet_infos] # Finally, interpret the items return interpret_items([], items)
def expand_raw_item(raw_item): """ Raw items that include searches must be expanded into more raw items. Input: Raw item. Output: Array of raw items. If raw item does not need expanding, this returns an 1-length array that contains original raw item, otherwise it contains the search result. You do not need to call resolve_items_into_infos on the returned raw_items. """ (bundle_info, subworksheet_info, value_obj, item_type, id, sort_key) = raw_item is_search = item_type == TYPE_DIRECTIVE and get_command( value_obj) == 'search' is_wsearch = item_type == TYPE_DIRECTIVE and get_command( value_obj) == 'wsearch' if is_search or is_wsearch: command = get_command(value_obj) keywords = value_obj[1:] raw_items = [] if is_search: keywords = rest_util.resolve_owner_in_keywords(keywords) search_result = local.model.search_bundles(request.user.user_id, keywords) if search_result['is_aggregate']: # Add None's for the 'id' and 'sort_key' of the tuple, since these # items are not really worksheet items. raw_items.append( markup_item(str(search_result['result'])) + (None, None)) else: bundle_uuids = search_result['result'] bundle_infos = rest_util.get_bundle_infos(bundle_uuids) for bundle_uuid in bundle_uuids: # Since bundle UUID's are queried first, we can't assume a UUID exists in # the subsequent bundle info query. if bundle_uuid in bundle_infos: raw_items.append( bundle_item(bundle_infos[bundle_uuid]) + (None, None)) elif is_wsearch: worksheet_infos = search_worksheets(keywords) for worksheet_info in worksheet_infos: raw_items.append( subworksheet_item(worksheet_info) + (None, None)) return raw_items else: return [raw_item]
def expand_raw_item(raw_item): """ Raw items that include searches must be expanded into more raw items. Input: Raw item. Output: Array of raw items. If raw item does not need expanding, this returns an 1-length array that contains original raw item, otherwise it contains the search result. You do not need to call resolve_items_into_infos on the returned raw_items. """ (bundle_info, subworksheet_info, value_obj, item_type) = raw_item is_search = item_type == TYPE_DIRECTIVE and get_command( value_obj) == 'search' is_wsearch = item_type == TYPE_DIRECTIVE and get_command( value_obj) == 'wsearch' if is_search or is_wsearch: command = get_command(value_obj) keywords = value_obj[1:] raw_items = [] if is_search: keywords = rest_util.resolve_owner_in_keywords(keywords) search_result = local.model.search_bundle_uuids( request.user.user_id, keywords) if not isinstance(search_result, list): raw_items.append(markup_item(str(search_result))) else: bundle_uuids = search_result bundle_infos = rest_util.get_bundle_infos(bundle_uuids) for bundle_uuid in bundle_uuids: raw_items.append(bundle_item(bundle_infos[bundle_uuid])) elif is_wsearch: worksheet_infos = search_worksheets(keywords) for worksheet_info in worksheet_infos: raw_items.append(subworksheet_item(worksheet_info)) return raw_items else: return [raw_item]
def perform_search_query(value_obj): """ Perform a search query and return the resulting raw items. Input: directive that is tokenized by formatting.string_to_tokens(), such as formatting.string_to_tokens("search 0x .limit=100") """ command = get_command(value_obj) is_search = command == 'search' is_wsearch = command == 'wsearch' if is_search or is_wsearch: keywords = value_obj[1:] raw_items = [] if is_search: keywords = rest_util.resolve_owner_in_keywords(keywords) search_result = local.model.search_bundles(request.user.user_id, keywords) if search_result['is_aggregate']: # Add None's for the 'id' and 'sort_key' of the tuple, since these # items are not really worksheet items. raw_items.append( markup_item(str(search_result['result'])) + (None, None)) else: bundle_uuids = search_result['result'] bundle_infos = rest_util.get_bundle_infos(bundle_uuids) for bundle_uuid in bundle_uuids: # Since bundle UUID's are queried first, we can't assume a UUID exists in # the subsequent bundle info query. if bundle_uuid in bundle_infos: raw_items.append( bundle_item(bundle_infos[bundle_uuid]) + (None, None)) elif is_wsearch: worksheet_infos = search_worksheets(keywords) for worksheet_info in worksheet_infos: raw_items.append( subworksheet_item(worksheet_info) + (None, None)) return raw_items else: # Not a search query return []
def expand_raw_item(raw_item): """ Raw items that include searches must be expanded into more raw items. Input: Raw item. Output: Array of raw items. If raw item does not need expanding, this returns an 1-length array that contains original raw item, otherwise it contains the search result. You do not need to call resolve_items_into_infos on the returned raw_items. """ (bundle_info, subworksheet_info, value_obj, item_type) = raw_item is_search = item_type == TYPE_DIRECTIVE and get_command(value_obj) == 'search' is_wsearch = item_type == TYPE_DIRECTIVE and get_command(value_obj) == 'wsearch' if is_search or is_wsearch: command = get_command(value_obj) keywords = value_obj[1:] raw_items = [] if is_search: keywords = rest_util.resolve_owner_in_keywords(keywords) search_result = local.model.search_bundles(request.user.user_id, keywords) if search_result['is_aggregate']: raw_items.append(markup_item(str(search_result['result']))) else: bundle_uuids = search_result['result'] bundle_infos = rest_util.get_bundle_infos(bundle_uuids) for bundle_uuid in bundle_uuids: raw_items.append(bundle_item(bundle_infos[bundle_uuid])) elif is_wsearch: worksheet_infos = search_worksheets(keywords) for worksheet_info in worksheet_infos: raw_items.append(subworksheet_item(worksheet_info)) return raw_items else: return [raw_item]