Skip to content
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

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions beanie/odm/operators/find/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,25 @@ class Sample(Document):

MongoDB doc:
<https://docs.mongodb.com/manual/reference/operator/query/text/>

Note: if you need to run a query against Azure Cosmos DB for MongoDB,
which does not support diacritic sensitivity yet, you can set
`diacritic_sensitive` argument to `None` to exclude it from the query.
"""

def __init__(
self,
search: str,
language: Optional[str] = None,
case_sensitive: bool = False,
diacritic_sensitive: bool = False,
diacritic_sensitive: Optional[bool] = False,
):
"""

:param search: str
:param language: Optional[str] = None
:param case_sensitive: bool = False
:param diacritic_sensitive: bool = False
:param diacritic_sensitive: Optional[bool] = False
"""
self.search = search
self.language = language
Expand All @@ -168,11 +172,14 @@ def query(self):
"$text": {
"$search": self.search,
"$caseSensitive": self.case_sensitive,
"$diacriticSensitive": self.diacritic_sensitive,
}
}
if self.language:
expression["$text"]["$language"] = self.language
if self.diacritic_sensitive is not None:
expression["$text"]["$diacriticSensitive"] = (
self.diacritic_sensitive
)
return expression


Expand Down
7 changes: 7 additions & 0 deletions tests/odm/operators/find/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ async def test_text():
"$diacriticSensitive": True,
}
}
q = Text("something", diacritic_sensitive=None)
assert q == {
"$text": {
"$search": "something",
"$caseSensitive": False,
}
}
q = Text("something", language="test")
assert q == {
"$text": {
Expand Down
Loading