Skip to content

Commit 3d6b650

Browse files
committed
add doc
change has_word ==> wholeword
1 parent 6bc1b83 commit 3d6b650

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

docs/guide/querying.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ expressions:
8686
* ``istartswith`` -- string field starts with value (case insensitive)
8787
* ``endswith`` -- string field ends with value
8888
* ``iendswith`` -- string field ends with value (case insensitive)
89+
* ``wholeword`` -- string field contains whole word
90+
* ``iwholeword`` -- string field contains whole word (case insensitive)
91+
* ``regex`` -- string field match by regex
92+
* ``iregex`` -- string field match by regex (case insensitive)
8993
* ``match`` -- performs an $elemMatch so you can match an entire document within an array
9094

9195

mongoengine/fields.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def prepare_query_value(self, op, value):
157157
regex = r"%s$"
158158
elif op == "exact":
159159
regex = r"^%s$"
160-
elif op == "has_word":
160+
elif op == "wholeword":
161161
regex = r"\b%s\b"
162162
elif op == "regex":
163163
regex = value
@@ -1094,14 +1094,7 @@ def lookup_member(self, member_name):
10941094

10951095
def prepare_query_value(self, op, value):
10961096
match_operators = [
1097-
"contains",
1098-
"icontains",
1099-
"startswith",
1100-
"istartswith",
1101-
"endswith",
1102-
"iendswith",
1103-
"exact",
1104-
"iexact",
1097+
*STRING_OPERATORS
11051098
]
11061099

11071100
if op in match_operators and isinstance(value, str):

mongoengine/queryset/transform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"iexact",
5454
"regex",
5555
"iregex",
56-
"has_word",
57-
"ihas_word",
56+
"wholeword",
57+
"iwholeword",
5858
)
5959
CUSTOM_OPERATORS = ("match",)
6060
MATCH_OPERATORS = (

tests/queryset/test_queryset.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,18 +1258,18 @@ def test_regex_query_shortcuts(self):
12581258
assert obj is None
12591259

12601260

1261-
# Test has_word
1262-
obj = self.Person.objects(name__has_word="Guido").first()
1261+
# Test wholeword
1262+
obj = self.Person.objects(name__wholeword="Guido").first()
12631263
assert obj == person
1264-
obj = self.Person.objects(name__has_word="rossum").first()
1264+
obj = self.Person.objects(name__wholeword="rossum").first()
12651265
assert obj is None
1266-
obj = self.Person.objects(name__has_word="Rossu").first()
1266+
obj = self.Person.objects(name__wholeword="Rossu").first()
12671267
assert obj is None
12681268

1269-
# Test ihas_word
1270-
obj = self.Person.objects(name__ihas_word="rOSSUM").first()
1269+
# Test iwholeword
1270+
obj = self.Person.objects(name__iwholeword="rOSSUM").first()
12711271
assert obj == person
1272-
obj = self.Person.objects(name__ihas_word="rOSSU").first()
1272+
obj = self.Person.objects(name__iwholeword="rOSSU").first()
12731273
assert obj is None
12741274

12751275
# Test regex
@@ -1374,8 +1374,8 @@ def test_filter_chaining_with_regex(self):
13741374
.filter(name__not__endswith="tum")\
13751375
.filter(name__icontains="VAN")\
13761376
.filter(name__regex="^Guido")\
1377-
.filter(name__has_word="Guido")\
1378-
.filter(name__has_word="van")
1377+
.filter(name__wholeword="Guido")\
1378+
.filter(name__wholeword="van")
13791379
assert people.count() == 1
13801380

13811381
def assertSequence(self, qs, expected):

0 commit comments

Comments
 (0)