def search_by_component():
    """
    This API is used to search the job based on the their component
    :return:
    """
    search_form = SearchByField(request.form)
    if request.method == "POST":
        Common.logger.info("search_by_component:Post API called")
        field_name = search_form.select.data
        field_value = search_form.data["search"].strip()
        fs = extracting_data_by_field(field_name=field_name,
                                      field_value=field_value)
        if fs.count() == 0:
            return render_template("404.html", title="404"), 404

        data_list = Common.collection_creation(fs)
        test_data_map = Common.test_map_details(data_list)
        if test_data_map == 500:
            Common.logger.warn(
                f"search_by_component:Internal server error comes while listing "
                f"the data_list={data_list}")
            return render_template("500.html", title="500"), 500
        return render_template("search_results.html",
                               List=data_list,
                               test_data_map=test_data_map)
    return render_template("component_search_by_field.html",
                           search_form=search_form)
def index(job_name=None, build_number=None, component_version=None):
    """
    This API is used to search the result based on the selected filtered options.
    :param str job_name:
    :param int build_number:
    :param str component_version:
    :return: Searched results and search job menu
    """
    search_form = JobSearchForm(request.form)
    if request.method == "POST":
        job_name = search_form.data["job_name"].strip()
        try:
            pattern_type = re.search(r"\w*-\w*", job_name).group()
        except AttributeError:
            Common.logger.warn(
                f"index:failed to search the job name: {job_name}")
            pattern_type = job_name
        build_number = search_form.data["build_number"]
        component_version = search_form.data["component_version"]

        fs = extracting_build_info(
            job_name=job_name,
            build_number=build_number,
            component_version=component_version,
        )
        if fs.count() == 0:
            return render_template("404.html", title="404"), 404
        data_list = Common.collection_creation(fs)
        return render_template(
            "search_results.html",
            List=data_list,
            pattern_type=pattern_type,
            data_display="True",
        )
    if job_name and build_number and component_version:
        fs = extracting_build_info(
            job_name=job_name,
            build_number=build_number,
            component_version=component_version,
        )
        if fs.count() == 0:
            return render_template("404.html", title="404"), 404
        data_list = Common.collection_creation(fs)
        test_data_map = Common.test_map_details(data_list)
        try:
            pattern_type = re.search(r"\w*-\w*",
                                     data_list[0]["Job-Name"]).group()
        except AttributeError:
            Common.logger.warn(
                f"index:failed to search the job: {data_list[0]['Job-Name']}")
            pattern_type = job_name

        return render_template(
            "search_results.html",
            List=data_list,
            pattern_type=pattern_type,
            data_display="False",
            test_data_map=test_data_map,
        )
    return render_template("search.html", form=search_form)