def tidy_survey_for_join(survey_df):
    """Tidy input survey for joining to results

    Melts, and adds survey_rank, survey_items_for_query columns.
    """
    survey_df = (
        survey_df.melt(id_vars=["Query"]).rename(
            columns={
                "variable": "survey_rank",
                "value": "wordform_text",
                "Query": "query",
            }
        )
    )[
        # this is to rearrange the column order
        ["query", "wordform_text", "survey_rank"]
    ]
    for i in [1, 2, 3]:
        survey_df.loc[survey_df["survey_rank"] == f"Nêhiyawêwin {i}", "survey_rank"] = i
    survey_df = survey_df.dropna()

    survey_items_for_query = (
        survey_df.groupby("query")["wordform_text"]
        .count()
        .rename("survey_items_for_query")
    )

    return survey_df.merge(survey_items_for_query, on="query")