Skip to content

Commit

Permalink
wekand docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasht86 committed Jan 6, 2025
1 parent 3abb3d2 commit ef8b1b1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions vespa/querybuilder/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,35 @@ def wand(

@staticmethod
def weakAnd(*conditions, annotations: Optional[Dict[str, Any]] = None) -> Condition:
"""Creates a weakAnd operator for less strict AND matching.
For more information, see https://docs.vespa.ai/en/reference/query-language-reference.html#weakand
Args:
*conditions (Condition): Variable number of conditions to combine
annotations (Optional[Dict[str, Any]]): Optional annotations like targetHits
Returns:
Condition: A weakAnd condition
Examples:
>>> import vespa.querybuilder as qb
>>> f1, f2 = qb.QueryField("f1"), qb.QueryField("f2")
>>> condition = qb.weakAnd(f1 == "v1", f2 == "v2")
>>> query = qb.select("*").from_("sd1").where(condition)
>>> str(query)
'select * from sd1 where weakAnd(f1 = "v1", f2 = "v2")'
>>> # With annotation
>>> condition = qb.weakAnd(
... f1 == "v1",
... f2 == "v2",
... annotations={"targetHits": 100}
... )
>>> query = qb.select("*").from_("sd1").where(condition)
>>> str(query)
'select * from sd1 where ({"targetHits": 100}weakAnd(f1 = "v1", f2 = "v2"))'
"""
conditions_str = ", ".join(cond.build() for cond in conditions)
expr = f"weakAnd({conditions_str})"
if annotations:
Expand Down

0 comments on commit ef8b1b1

Please sign in to comment.