nodes: 0, module; 1, function_definition; 2, function_name:query; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, if_statement; 14, expression_statement; 15, comment:# Use shards parameter only if there are several cores active; 16, if_statement; 17, comment:# Prepare filters; 18, if_statement; 19, comment:# Append sorting parameters; 20, if_statement; 21, comment:# Do request to Solr server to default endpoint (other cores will be queried with shard functionality); 22, assert_statement; 23, expression_statement; 24, expression_statement; 25, if_statement; 26, assert_statement; 27, comment:# Check for response status; 28, if_statement; 29, assert_statement; 30, expression_statement; 31, return_statement; 32, identifier:filters; 33, None; 34, identifier:columns; 35, None; 36, identifier:sort; 37, None; 38, identifier:start; 39, integer:0; 40, identifier:rows; 41, integer:30; 42, comment:"""
          Queries Solr and returns results
  
          query - Text query to search for
          filters - dictionary of filters to apply when searching in form of { "field":"filter_value" }
          columns - columns to return, list of strings
          sort - list of fields to sort on in format of ["field asc", "field desc", ... ]
          start - start number of first result (used in pagination)
          rows - number of rows to return (used for pagination, defaults to 30)
          """; 43, not_operator; 44, block; 45, assignment; 46, comparison_operator:len(self.endpoints) > 1; 47, block; 48, not_operator; 49, block; 50, not_operator; 51, block; 52, comparison_operator:self.default_endpoint in self.endpoints; 53, assignment; 54, assignment; 55, not_operator; 56, block; 57, comparison_operator:"responseHeader" in results; 58, not_operator; 59, block; 60, comparison_operator:"response" in results; 61, assignment; 62, identifier:result_obj; 63, identifier:columns; 64, expression_statement; 65, identifier:fields; 66, dictionary; 67, call; 68, integer:1; 69, expression_statement; 70, comparison_operator:filters is None; 71, expression_statement; 72, for_statement; 73, expression_statement; 74, comparison_operator:sort is None; 75, expression_statement; 76, attribute; 77, attribute; 78, identifier:request_url; 79, call; 80, identifier:results; 81, call; 82, identifier:results; 83, return_statement; 84, string:"responseHeader"; 85, identifier:results; 86, comparison_operator:results.get("responseHeader").get("status") == 0; 87, expression_statement; 88, return_statement; 89, string:"response"; 90, identifier:results; 91, identifier:result_obj; 92, call; 93, assignment; 94, pair; 95, pair; 96, comment:# Return facets as JSON objects; 97, pair; 98, comment:# Return score along with results; 99, pair; 100, pair; 101, pair; 102, identifier:len; 103, argument_list; 104, assignment; 105, identifier:filters; 106, None; 107, assignment; 108, pattern_list; 109, call; 110, block; 111, assignment; 112, identifier:sort; 113, None; 114, assignment; 115, identifier:self; 116, identifier:default_endpoint; 117, identifier:self; 118, identifier:endpoints; 119, identifier:_get_url; 120, argument_list; 121, attribute; 122, argument_list; 123, None; 124, call; 125, integer:0; 126, call; 127, None; 128, attribute; 129, argument_list; 130, identifier:columns; 131, list; 132, string:"q"; 133, identifier:query; 134, string:"json.nl"; 135, string:"map"; 136, string:"fl"; 137, call; 138, string:"start"; 139, call; 140, string:"rows"; 141, call; 142, string:"wt"; 143, string:"json"; 144, attribute; 145, subscript; 146, call; 147, identifier:filter_list; 148, list; 149, identifier:filter_field; 150, identifier:value; 151, attribute; 152, argument_list; 153, expression_statement; 154, subscript; 155, call; 156, subscript; 157, call; 158, subscript; 159, string:"select"; 160, identifier:self; 161, identifier:_send_solr_query; 162, identifier:request_url; 163, identifier:fields; 164, attribute; 165, argument_list; 166, attribute; 167, argument_list; 168, identifier:self; 169, identifier:_parse_response; 170, identifier:results; 171, string:"*"; 172, string:"score"; 173, attribute; 174, argument_list; 175, identifier:str; 176, argument_list; 177, identifier:str; 178, argument_list; 179, identifier:self; 180, identifier:endpoints; 181, identifier:fields; 182, string:"shards"; 183, attribute; 184, argument_list; 185, identifier:filters; 186, identifier:items; 187, call; 188, identifier:fields; 189, string:"fq"; 190, attribute; 191, argument_list; 192, identifier:fields; 193, string:"sort"; 194, attribute; 195, argument_list; 196, attribute; 197, attribute; 198, call; 199, identifier:get; 200, string:"status"; 201, identifier:logger; 202, identifier:error; 203, string:"Server error while retrieving results: %s"; 204, identifier:results; 205, string:","; 206, identifier:join; 207, identifier:columns; 208, identifier:start; 209, identifier:rows; 210, identifier:self; 211, identifier:_get_shards; 212, attribute; 213, argument_list; 214, string:" AND "; 215, identifier:join; 216, identifier:filter_list; 217, string:","; 218, identifier:join; 219, identifier:sort; 220, identifier:self; 221, identifier:endpoints; 222, identifier:self; 223, identifier:default_endpoint; 224, attribute; 225, argument_list; 226, identifier:filter_list; 227, identifier:append; 228, binary_operator:"%s:%s" % (filter_field, value); 229, identifier:results; 230, identifier:get; 231, string:"responseHeader"; 232, string:"%s:%s"; 233, tuple; 234, identifier:filter_field; 235, identifier:value
code: def query(self, query, filters=None, columns=None, sort=None, start=0, rows=30):
          """
          Queries Solr and returns results
  
          query - Text query to search for
          filters - dictionary of filters to apply when searching in form of { "field":"filter_value" }
          columns - columns to return, list of strings
          sort - list of fields to sort on in format of ["field asc", "field desc", ... ]
          start - start number of first result (used in pagination)
          rows - number of rows to return (used for pagination, defaults to 30)
          """
  
          if not columns:
              columns = ["*", "score"]
  
          fields = {"q": query,
                   "json.nl" :"map",           # Return facets as JSON objects
                   "fl": ",".join(columns),    # Return score along with results
                   "start": str(start),
                   "rows": str(rows),
                   "wt": "json"}
  
          # Use shards parameter only if there are several cores active
          if len(self.endpoints) > 1:
              fields["shards"] = self._get_shards()
  
          # Prepare filters
          if not filters is None:
              filter_list = []
              for filter_field, value in filters.items():
                  filter_list.append("%s:%s" % (filter_field, value))
              fields["fq"] = " AND ".join(filter_list)
  
          # Append sorting parameters
          if not sort is None:
              fields["sort"] = ",".join(sort)
  
          # Do request to Solr server to default endpoint (other cores will be queried with shard functionality)
          assert self.default_endpoint in self.endpoints
          request_url = _get_url(self.endpoints[self.default_endpoint], "select")
          results = self._send_solr_query(request_url, fields)
          if not results:
              return None
  
          assert "responseHeader" in results
          # Check for response status
          if not results.get("responseHeader").get("status") == 0:
              logger.error("Server error while retrieving results: %s", results)
              return None
  
          assert "response" in results
  
          result_obj = self._parse_response(results)
          return result_obj