code: def _validate_query(query):
      query = deepcopy(query)
      if query["q"] == BLANK_QUERY["q"]:
          raise ValueError("No query specified.")
      query["q"] = _clean_query_string(query["q"])
      if query["limit"] is None:
          query["limit"] = SEARCH_LIMIT if query["advanced"] else NONADVANCED_LIMIT
      elif query["limit"] > SEARCH_LIMIT:
          warnings.warn('Reduced result limit from {} to the Search maximum: {}'
                        .format(query["limit"], SEARCH_LIMIT), RuntimeWarning)
          query["limit"] = SEARCH_LIMIT
      for key, val in BLANK_QUERY.items():
          if query.get(key, float('nan')) == val:
              query.pop(key)
      to_remove = [field for field in query.keys() if field not in BLANK_QUERY.keys()]
      [query.pop(field) for field in to_remove]
      return query