Search returning limited results


I am brand new to the world of Python and Mongo, but I am really enjoying it. I have made an index that contains one of my collections and, to be fair, everything seems to work as expected, except for the number of results.

I am doing a search of users on my app:

@app.route("/search_profiles", methods=["GET", "POST"])

def search_profiles():

    user = session["user"] or None

    user_profile = mongo.db.users.find_one({"username": user})

    search_profiles = request.form.get("search_profiles")

    profiles = mongo.db.users.find({"$text": {"$search": search_profiles}})

    return render_template("search_profiles.html", profiles=profiles, user=user_profile)

This does return the searches if a user searches near identical words. But the problem begins to show when a username is test1234 (for example) and carries both letters and numbers.

If I search for “test” in my app I return users such as:



But I do not return

How do I enhance the search to be able to accept that some people use numbers in their username but people are really only searching for the text of the username?

Thanks kindly for looking at this. I have searched for this and seen some similar instances of this occurring, but not a fix that seems to work.