nodes: 0, module; 1, function_definition; 2, function_name:search_in_hdx; 3, parameters; 4, comment:# type: (Optional[str], Optional[Configuration], int, Any) -> List['Dataset']; 5, block; 6, identifier:cls; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, dictionary_splat_pattern; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, while_statement; 18, if_statement; 19, return_statement; 20, identifier:query; 21, string; 22, identifier:configuration; 23, None; 24, identifier:page_size; 25, integer:1000; 26, identifier:kwargs; 27, comment:"""Searches for datasets in HDX
  
          Args:
              query (Optional[str]): Query (in Solr format). Defaults to '*:*'.
              configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.
              page_size (int): Size of page to return. Defaults to 1000.
              **kwargs: See below
              fq (string): Any filter queries to apply
              sort (string): Sorting of the search results. Defaults to 'relevance asc, metadata_modified desc'.
              rows (int): Number of matching rows to return. Defaults to all datasets (sys.maxsize).
              start (int): Offset in the complete result for where the set of returned datasets should begin
              facet (string): Whether to enable faceted results. Default to True.
              facet.mincount (int): Minimum counts for facet fields should be included in the results
              facet.limit (int): Maximum number of values the facet fields return (- = unlimited). Defaults to 50.
              facet.field (List[str]): Fields to facet upon. Default is empty.
              use_default_schema (bool): Use default package schema instead of custom schema. Defaults to False.
  
          Returns:
              List[Dataset]: list of datasets resulting from query
          """; 28, assignment; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, boolean_operator; 34, comment:# if the count values vary for multiple calls, then must redo query; 35, block; 36, boolean_operator; 37, block; 38, identifier:all_datasets; 39, string_content:*:*; 40, identifier:dataset; 41, call; 42, identifier:total_rows; 43, call; 44, identifier:start; 45, call; 46, identifier:all_datasets; 47, None; 48, identifier:attempts; 49, integer:0; 50, comparison_operator:attempts < cls.max_attempts; 51, comparison_operator:all_datasets is None; 52, expression_statement; 53, expression_statement; 54, for_statement; 55, if_statement; 56, comparison_operator:attempts == cls.max_attempts; 57, comparison_operator:all_datasets is None; 58, raise_statement; 59, identifier:Dataset; 60, argument_list; 61, attribute; 62, argument_list; 63, attribute; 64, argument_list; 65, identifier:attempts; 66, attribute; 67, identifier:all_datasets; 68, None; 69, assignment; 70, assignment; 71, identifier:page; 72, call; 73, block; 74, boolean_operator; 75, comment:# Make sure counts are all same for multiple calls to HDX; 76, block; 77, else_clause; 78, identifier:attempts; 79, attribute; 80, identifier:all_datasets; 81, None; 82, call; 83, keyword_argument; 84, identifier:kwargs; 85, identifier:get; 86, string; 87, attribute; 88, identifier:kwargs; 89, identifier:get; 90, string; 91, integer:0; 92, identifier:cls; 93, identifier:max_attempts; 94, identifier:all_datasets; 95, call; 96, identifier:counts; 97, call; 98, identifier:range; 99, argument_list; 100, expression_statement; 101, expression_statement; 102, expression_statement; 103, expression_statement; 104, expression_statement; 105, expression_statement; 106, expression_statement; 107, if_statement; 108, identifier:all_datasets; 109, comparison_operator:len(counts) != 1; 110, expression_statement; 111, expression_statement; 112, block; 113, identifier:cls; 114, identifier:max_attempts; 115, identifier:HDXError; 116, argument_list; 117, identifier:configuration; 118, identifier:configuration; 119, string_content:rows; 120, identifier:cls; 121, identifier:max_int; 122, string_content:start; 123, identifier:list; 124, argument_list; 125, identifier:set; 126, argument_list; 127, binary_operator:total_rows // page_size + 1; 128, assignment; 129, assignment; 130, assignment; 131, assignment; 132, assignment; 133, assignment; 134, assignment; 135, identifier:result; 136, block; 137, else_clause; 138, call; 139, integer:1; 140, assignment; 141, augmented_assignment; 142, expression_statement; 143, comment:# check for duplicates (shouldn't happen); 144, if_statement; 145, string; 146, binary_operator:total_rows // page_size; 147, integer:1; 148, identifier:pagetimespagesize; 149, binary_operator:page * page_size; 150, subscript; 151, binary_operator:start + pagetimespagesize; 152, identifier:rows_left; 153, binary_operator:total_rows - pagetimespagesize; 154, identifier:rows; 155, call; 156, subscript; 157, identifier:rows; 158, pattern_list; 159, call; 160, identifier:datasets; 161, call; 162, expression_statement; 163, if_statement; 164, block; 165, identifier:len; 166, argument_list; 167, identifier:all_datasets; 168, None; 169, identifier:attempts; 170, integer:1; 171, assignment; 172, comparison_operator:len(ids) != len(set(ids)); 173, block; 174, string_content:Maximum attempts reached for searching for datasets!; 175, identifier:total_rows; 176, identifier:page_size; 177, identifier:page; 178, identifier:page_size; 179, identifier:kwargs; 180, string; 181, identifier:start; 182, identifier:pagetimespagesize; 183, identifier:total_rows; 184, identifier:pagetimespagesize; 185, identifier:min; 186, argument_list; 187, identifier:kwargs; 188, string; 189, identifier:_; 190, identifier:result; 191, attribute; 192, argument_list; 193, identifier:list; 194, argument_list; 195, assignment; 196, identifier:count; 197, block; 198, else_clause; 199, expression_statement; 200, identifier:counts; 201, identifier:ids; 202, list_comprehension; 203, call; 204, call; 205, expression_statement; 206, expression_statement; 207, string_content:start; 208, identifier:rows_left; 209, identifier:page_size; 210, string_content:rows; 211, identifier:dataset; 212, identifier:_read_from_hdx; 213, string; 214, identifier:query; 215, string; 216, subscript; 217, dictionary_splat; 218, identifier:count; 219, call; 220, expression_statement; 221, expression_statement; 222, for_statement; 223, expression_statement; 224, if_statement; 225, block; 226, call; 227, subscript; 228, for_in_clause; 229, identifier:len; 230, argument_list; 231, identifier:len; 232, argument_list; 233, assignment; 234, augmented_assignment; 235, string_content:dataset; 236, string_content:q; 237, call; 238, string; 239, identifier:kwargs; 240, attribute; 241, argument_list; 242, call; 243, assignment; 244, identifier:datasetdict; 245, subscript; 246, block; 247, augmented_assignment; 248, comparison_operator:no_results < rows; 249, block; 250, break_statement; 251, attribute; 252, argument_list; 253, identifier:dataset; 254, string; 255, identifier:dataset; 256, identifier:all_datasets; 257, identifier:ids; 258, call; 259, identifier:all_datasets; 260, None; 261, identifier:attempts; 262, integer:1; 263, attribute; 264, argument_list; 265, string_content:search; 266, identifier:result; 267, identifier:get; 268, string; 269, None; 270, attribute; 271, argument_list; 272, identifier:no_results; 273, call; 274, identifier:result; 275, string; 276, expression_statement; 277, expression_statement; 278, expression_statement; 279, expression_statement; 280, expression_statement; 281, identifier:all_datasets; 282, identifier:datasets; 283, identifier:no_results; 284, identifier:rows; 285, break_statement; 286, identifier:logger; 287, identifier:debug; 288, identifier:result; 289, string_content:id; 290, identifier:set; 291, argument_list; 292, identifier:Dataset; 293, identifier:actions; 294, string_content:count; 295, identifier:counts; 296, identifier:add; 297, identifier:count; 298, identifier:len; 299, argument_list; 300, string_content:results; 301, assignment; 302, assignment; 303, assignment; 304, call; 305, call; 306, identifier:ids; 307, subscript; 308, identifier:dataset; 309, call; 310, attribute; 311, call; 312, attribute; 313, identifier:datasetdict; 314, attribute; 315, argument_list; 316, attribute; 317, argument_list; 318, identifier:result; 319, string; 320, identifier:Dataset; 321, argument_list; 322, identifier:dataset; 323, identifier:old_data; 324, identifier:dict; 325, argument_list; 326, identifier:dataset; 327, identifier:data; 328, identifier:dataset; 329, identifier:_dataset_create_resources; 330, identifier:datasets; 331, identifier:append; 332, identifier:dataset; 333, string_content:results; 334, keyword_argument; 335, identifier:configuration; 336, identifier:configuration
code: def search_in_hdx(cls, query='*:*', configuration=None, page_size=1000, **kwargs):
          # type: (Optional[str], Optional[Configuration], int, Any) -> List['Dataset']
          """Searches for datasets in HDX
  
          Args:
              query (Optional[str]): Query (in Solr format). Defaults to '*:*'.
              configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration.
              page_size (int): Size of page to return. Defaults to 1000.
              **kwargs: See below
              fq (string): Any filter queries to apply
              sort (string): Sorting of the search results. Defaults to 'relevance asc, metadata_modified desc'.
              rows (int): Number of matching rows to return. Defaults to all datasets (sys.maxsize).
              start (int): Offset in the complete result for where the set of returned datasets should begin
              facet (string): Whether to enable faceted results. Default to True.
              facet.mincount (int): Minimum counts for facet fields should be included in the results
              facet.limit (int): Maximum number of values the facet fields return (- = unlimited). Defaults to 50.
              facet.field (List[str]): Fields to facet upon. Default is empty.
              use_default_schema (bool): Use default package schema instead of custom schema. Defaults to False.
  
          Returns:
              List[Dataset]: list of datasets resulting from query
          """
  
          dataset = Dataset(configuration=configuration)
          total_rows = kwargs.get('rows', cls.max_int)
          start = kwargs.get('start', 0)
          all_datasets = None
          attempts = 0
          while attempts < cls.max_attempts and all_datasets is None:  # if the count values vary for multiple calls, then must redo query
              all_datasets = list()
              counts = set()
              for page in range(total_rows // page_size + 1):
                  pagetimespagesize = page * page_size
                  kwargs['start'] = start + pagetimespagesize
                  rows_left = total_rows - pagetimespagesize
                  rows = min(rows_left, page_size)
                  kwargs['rows'] = rows
                  _, result = dataset._read_from_hdx('dataset', query, 'q', Dataset.actions()['search'], **kwargs)
                  datasets = list()
                  if result:
                      count = result.get('count', None)
                      if count:
                          counts.add(count)
                          no_results = len(result['results'])
                          for datasetdict in result['results']:
                              dataset = Dataset(configuration=configuration)
                              dataset.old_data = dict()
                              dataset.data = datasetdict
                              dataset._dataset_create_resources()
                              datasets.append(dataset)
                          all_datasets += datasets
                          if no_results < rows:
                              break
                      else:
                          break
                  else:
                      logger.debug(result)
              if all_datasets and len(counts) != 1:  # Make sure counts are all same for multiple calls to HDX
                  all_datasets = None
                  attempts += 1
              else:
                  ids = [dataset['id'] for dataset in all_datasets]  # check for duplicates (shouldn't happen)
                  if len(ids) != len(set(ids)):
                      all_datasets = None
                      attempts += 1
          if attempts == cls.max_attempts and all_datasets is None:
              raise HDXError('Maximum attempts reached for searching for datasets!')
          return all_datasets