Search code examples
pythonmongodbpymongopymodm

How to create a full text index with pymodm


I'm not completely sure how to create a full text index with PyModm.

My Meta class looks like this:

lass Meta:
        write_concern = WriteConcern(j=True)
        indexes = [
            pymongo.IndexModel([("name", "text"), ("description", "text")])
        ]

However, when I attempt to run the raw query using get_queryset().raw()

{
    "$text": {"$search": query}
}

No results are returned.

Thanks in advance.


Solution

  • Figured it out

    Apparently, I just needed to provide a list of (field, 'text') tuples

    i.e.

    index = [
        pymongo.IndexModel([
            ("first_field", "text"),
            ("second_field", "text")
        ])
    ]