Skip to content

Commit 77f0a84

Browse files
committed
added score expression
1 parent 54685a8 commit 77f0a84

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/google-cloud-firestore/google/cloud/firestore_v1/pipeline_expressions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,22 @@ def __init__(self):
29382938
super().__init__("rand", [], use_infix_repr=False)
29392939

29402940

2941+
class Score(FunctionExpression):
2942+
"""Evaluates to the search score that reflects the topicality of the document
2943+
to all of the text predicates (`queryMatch`)
2944+
in the search query. If `SearchOptions.query` is not set or does not contain
2945+
any text predicates, then this topicality score will always be `0`.
2946+
2947+
Note: This Expression can only be used within a `Search` stage.
2948+
2949+
Returns:
2950+
A new `Expression` representing the score operation.
2951+
"""
2952+
2953+
def __init__(self):
2954+
super().__init__("score", [], use_infix_repr=False)
2955+
2956+
29412957
class DocumentMatches(BooleanExpression):
29422958
"""Creates a boolean expression for a document match query.
29432959

packages/google-cloud-firestore/tests/unit/v1/test_pipeline_expressions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,12 @@ def test_document_matches(self):
820820
assert instance.params == [arg1]
821821
assert repr(instance) == "DocumentMatches(Query)"
822822

823+
def test_score(self):
824+
instance = expr.Score()
825+
assert instance.name == "score"
826+
assert instance.params == []
827+
assert repr(instance) == "Score()"
828+
823829
def test_greater_than_or_equal(self):
824830
arg1 = self._make_arg("Left")
825831
arg2 = self._make_arg("Right")

0 commit comments

Comments
 (0)