Leave out titles by phrase: an exclude gate mode and a title gate field
A role whose title holds one of the agent's phrases as whole words is gated with the phrase as its reason, a favourite's too. The agent form has a Leave out titles line under Where. function = sales could not do it, since the classifier files Solutions Engineer and pre-sales under sales. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e827665dd
commit
8c6ea0ffb6
8 files changed
+116
-21
No files matched your search
+16
-4
@@ -219,6 +219,13 @@ def _gate_sql(gate: Gate, gaz: places.Gazetteer) -> tuple[str, str, list[Any]]:
|
||||
if gate.field == "place":
|
||||
match, params = _places_sql(values, gaz, table="r")
|
||||
return "r.place = ''", match, params
|
||||
if gate.field == "title":
|
||||
# Whole words of the folded title: " account executive " inside
|
||||
# " enterprise account executive uk ". A fold drops `%` and `_`, so a
|
||||
# value cannot smuggle a LIKE wildcard in.
|
||||
words = [f"% {title_key(v)} %" for v in values if title_key(v)]
|
||||
match = " OR ".join("(' ' || r.title_key || ' ') LIKE ?" for _ in words) or "0"
|
||||
return "r.title_key = ''", f"({match})", words
|
||||
if gate.field == "company":
|
||||
keys = [company_key(v) for v in values]
|
||||
return ("r.company_key = ''",
|
||||
@@ -1830,10 +1837,15 @@ class Store:
|
||||
params: list[Any] = []
|
||||
gaz = self.gazetteer()
|
||||
for n, gate in enumerate(gates):
|
||||
empty, match, values = _gate_sql(gate, gaz)
|
||||
columns.append(
|
||||
f"CASE WHEN {empty} THEN -1 WHEN {match} THEN 1 ELSE 0 END AS g{n}")
|
||||
params += values
|
||||
# An exclude gate says which of its values matched: one WHEN each.
|
||||
parts = ([gate.model_copy(update={"values": [v]}) for v in gate.values]
|
||||
if gate.mode == "exclude" else [gate])
|
||||
whens = []
|
||||
for k, part in enumerate(parts, 1):
|
||||
empty, match, values = _gate_sql(part, gaz)
|
||||
whens.append(f"WHEN {match} THEN {k}")
|
||||
params += values
|
||||
columns.append(f"CASE WHEN {empty} THEN -1 {' '.join(whens)} ELSE 0 END AS g{n}")
|
||||
select = ", ".join(["r.uid", "r.posted_at",
|
||||
"COALESCE(ac.affinity, 0) AS affinity", *columns])
|
||||
rows = self._rows(
|
||||
|
||||
Reference in new issue
Block a user