def METHOD_NAME(
    ctx,
    query,
    times,
    time_ranges,
    labels,
    header,
    return_fields,
    order,
    limit,
    saved_search,
    describe,
    show_internal_columns,
):
    """Search and explore."""
    sketch = ctx.obj.sketch
    output_format = ctx.obj.output_format
    search_obj = search.Search(sketch=sketch)
    new_line = True
    if output_format == "csv":
        new_line = False
    # Construct query from saved search and return early.
    if saved_search:
        search_obj.from_saved(saved_search)
        if limit:
            search_obj.max_entries = limit
        if describe:
            describe_query(search_obj)
            return
        click.echo(
            format_output(search_obj, output_format, header, show_internal_columns),
            nl=new_line,
        )
        return
    # Construct the query from flags.
    # TODO (berggren): Add support for query DSL.
    search_obj.query_string = query
    if return_fields:
        search_obj.return_fields = return_fields
    if limit:
        search_obj.max_entries = limit
    if order == "asc":
        search_obj.order_ascending()
    elif order == "desc":
        search_obj.order_descending()
    # TODO: Add term chips.
    if time_ranges:
        for time_range in time_ranges:
            try:
                range_chip = search.DateRangeChip()
                range_chip.add_start_time(time_range[0])
                range_chip.add_end_time(time_range[1])
                search_obj.add_chip(range_chip)
            except ValueError:
                click.echo("Error parsing date (make sure it is ISO formatted)")
                sys.exit(1)
    # TODO (berggren): This should support dates like 2021-02-12 and then
    # convert to ISO format.
    if times:
        for time in times:
            try:
                range_chip = search.DateRangeChip()
                range_chip.add_start_time(time)
                range_chip.add_end_time(time)
                search_obj.add_chip(range_chip)
            except ValueError:
                click.echo("Error parsing date (make sure it is ISO formatted)")
                sys.exit(1)
    if labels:
        for label in labels:
            label_chip = search.LabelChip()
            if label == "star":
                label_chip.use_star_label()
            elif label == "comment":
                label_chip.use_comment_label()
            else:
                label_chip.label = label
            search_obj.add_chip(label_chip)
    if describe:
        describe_query(search_obj)
        return
    click.echo(
        format_output(search_obj, output_format, header, show_internal_columns),
        nl=new_line,
    )