-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text Search? #102
Comments
For this you need a text index. Here is the MongoDB doc: https://docs.mongodb.com/manual/core/index-text/ The simplest way to add it is: class Location(Document):
name: Indexed(str, index_type=TEXT)
private: bool = False
class Collection:
name = "locations" Then you can use operator Text or native MongoDB query. Full working example: import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
from pymongo import TEXT
from beanie import Document, Indexed, init_beanie
from beanie.operators import Text
MONGO_URI = "YOUR URI"
class Location(Document):
name: Indexed(str, index_type=TEXT)
private: bool = False
class Collection:
name = "locations"
async def main():
db = AsyncIOMotorClient(MONGO_URI).test_db
await init_beanie(database=db, document_models=[Location])
# await Location(name="some test New York bla bla").insert()
# await Location(name="some test bla bla").insert()
l = await Location.find(Text("New York")).to_list()
print(l)
asyncio.run(main()) Thank you for the issue. I'll add this point to the doc. |
This issue is stale because it has been open 30 days with no activity. |
This issue was closed because it has been stalled for 14 days with no activity. |
I couldn't find anything in the docs to do text search (https://docs.mongodb.com/manual/reference/operator/query/text/)
I have a document :
I want to do a search like "where name contains 'New York'"
Is this possible at the moment?
The text was updated successfully, but these errors were encountered: