-
Notifications
You must be signed in to change notification settings - Fork 224
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
Make diacritic_sensitive
parameter optional to support $text operator on Cosmos DB
#1089
Conversation
This fixes [the issue](BeanieODM#1088) with Azure CosmosDB for MongoDB which does not support diacritic sensitivity.
To use text search with Azure CosmosDB for MongoDB, set import asyncio
import os
from beanie import Document, Indexed, init_beanie
from beanie.operators import Text
from motor.motor_asyncio import AsyncIOMotorClient
from pymongo import TEXT
class Dish(Document):
name: Indexed(str, index_type=TEXT)
async def example():
client = AsyncIOMotorClient(os.environ["COSMOSDB_CONNECTION"])
await init_beanie(database=client["test"], document_models=[Dish])
names = [
"Ravioli",
"Spaghetti al pomodoro",
"Tagliatelle al pomodoro",
]
for name in names:
dish = Dish(name=name)
await dish.insert()
result = await Dish.find(Text("pomodoro", diacritic_sensitive=None)).to_list()
print("result", result)
if __name__ == "__main__":
asyncio.run(example()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mykolaskrynnyk, thank you for your contribution!
Please update the docstring to explain why diacritic_sensitive
would be set to None
.
Please update this test to address the case where the diacritic_sensitive
would be set to None
. You could test this case just below this block.
https://github.com/mykolaskrynnyk/beanie/blob/0773aed151acb30dfcc4448cdbc26326c7366a53/tests/odm/operators/find/test_evaluation.py#L52C1-L59C6
diacritic_sensitive
parameter optional to support $text operator on Cosmos DB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mykolaskrynnyk , thank you for your contribution, it looks good.
Just one minor thing, according to MongoDB documentation, $language and $caseSensitive are optional as well (do not need to be provided).
Could you please make these optional as well? Can be a separate PR.
https://www.mongodb.com/docs/manual/reference/operator/query/text/
@staticxterm , it would've been better if all three parameters had been made optional and set to Option 1 I guess this is what you suggest: # @@ class Text(BaseFindEvaluationOperator):
search: str,
language: Optional[str] = None,
case_sensitive: Optional[bool] = False,
diacritic_sensitive: Optional[bool] = False,
): Which is a non-breaking change but it doesn't seem like there is any use-case for that at this point. Option 2 I think this option would be a lot nicer (and work out of the box for use cases like version 2 text indices) but it does introduce a breaking change: # @@ class Text(BaseFindEvaluationOperator):
search: str,
language: Optional[str] = None,
case_sensitive: Optional[bool] = None,
diacritic_sensitive: Optional[bool] = None,
): Any additional thoughts on the topic? |
Hi @mykolaskrynnyk, |
@staticxterm , I'll make another PR for case sensitivity to keep this one focused on the issue. In the meantime, can someone do the third review to get this out of the door? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll review it after all change requests are solved.
@Riverfount , I don't think there are any outstanding change requests. Can you clarify what you mean? |
There is a "Review required" in the PR. Do you know if that is a change request to solve, or not? |
@Riverfount , if you refer to the change request from @adeelsohailahmed, it has already been solved in subsequent commits and approved accordingly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job
Closes #1088.