Skip to content

Commit 7735351

Browse files
committed
improve coverage
1 parent 428fe91 commit 7735351

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

django_mongodb_backend/expressions/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def as_mql(self, compiler, connection):
989989
if self.exact:
990990
params["exact"] = self.exact.value
991991
if self.filter:
992-
params["filter"] = self.filter.as_mql(compiler, connection)
992+
params["filter"] = self.filter.value
993993
return {"$vectorSearch": params}
994994

995995

tests/atlas_search_/test_search.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,11 @@ def setUpClass(cls):
980980
"numDimensions": 3,
981981
"similarity": "cosine",
982982
"quantization": "scalar",
983-
}
983+
},
984+
{
985+
"type": "filter",
986+
"path": "number",
987+
},
984988
]
985989
},
986990
type="vectorSearch",
@@ -999,14 +1003,22 @@ def setUp(self):
9991003
body="This article is about pasta",
10001004
plot_embedding=[0.9, 0.8, 0.7],
10011005
)
1006+
Article.objects.create(
1007+
headline="Local team wins championship",
1008+
number=3,
1009+
body="This article is about sports",
1010+
plot_embedding=[-0.1, 0.7, 0.7],
1011+
)
10021012

10031013
def test_vector_search(self):
10041014
vector_query = [0.1, 0.2, 0.3]
10051015
expr = SearchVector(
10061016
path="plot_embedding",
10071017
query_vector=vector_query,
10081018
num_candidates=5,
1009-
limit=2,
1019+
limit=3,
1020+
filter={"number": {"$lt": 3}},
1021+
exact=False,
10101022
)
10111023
qs = Article.objects.annotate(score=expr).order_by("-score")
10121024
self.assertCountEqual(qs, [self.mars, self.cooking])

0 commit comments

Comments
 (0)