:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(search): show only exact matches unless there are none (#68724)
Paul D'Ambra279b31844d9b
diff --git a/posthog/api/cohort.py b/posthog/api/cohort.pyindex fd98d4770700..dbc276a9e0d8 100644--- a/posthog/api/cohort.py+++ b/posthog/api/cohort.py@@ -45,7 +45,13 @@ from posthog.constants import LIMIT, OFFSETfrom posthog.event_usage import report_user_actionfrom posthog.exceptions_capture import capture_exceptionfrom posthog.helpers.impersonation import is_impersonated-from posthog.helpers.trigram_search import MAX_SEARCH_LENGTH, NAME_FIELD, apply_trigram_search, normalize_search_term+from posthog.helpers.trigram_search import (+ MAX_SEARCH_LENGTH,+ NAME_FIELD,+ apply_trigram_search,+ drop_similar_when_exact_exists,+ normalize_search_term,+)from posthog.hogql_queries.actors_query_runner import ActorsQueryRunnerfrom posthog.hogql_queries.query_runner import ExecutionModefrom posthog.metrics import LABEL_TEAM_ID@@ -1415,11 +1421,11 @@ def get_cohorts_using_cohort(cohort: Cohort) -> QuerySet[Cohort]:type=OpenApiTypes.STR,location=OpenApiParameter.QUERY,description=(- "Optional. Match against cohort `name`. Returns case-insensitive substring matches and "- "fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered "- "exact-first then by relevance; each result's `search_match_type` is `exact` or `similar`. "- "When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries "- "return a 400 error."+ "Optional. Match against cohort `name`. Returns exact (case-insensitive substring) "+ "matches only; if no exact match exists, returns similar (fuzzy trigram — typos, "+ "transpositions, prefix-as-you-type) matches instead. Each result's `search_match_type` "+ "is `exact` or `similar`. Results are ordered by relevance. When omitted, cohorts are ordered newest-first. Capped at "+ "200 characters; longer queries return a 400 error."),),OpenApiParameter(@@ -1544,6 +1550,9 @@ class CohortViewSet(TeamAndOrgViewSetMixin, ForbidDestroyModel, viewsets.ModelVireturn queryset+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+@extend_schema(parameters=[OpenApiParameter(diff --git a/posthog/api/organization_member.py b/posthog/api/organization_member.pyindex 930ceb3cc15a..14a8423c104f 100644--- a/posthog/api/organization_member.py+++ b/posthog/api/organization_member.py@@ -31,6 +31,7 @@ from posthog.helpers.trigram_search import (MAX_SEARCH_LENGTH,TrigramSearchField,apply_trigram_search,+ drop_similar_when_exact_exists,normalize_search_term,)from posthog.models import OrganizationMembership@@ -155,7 +156,7 @@ class OrganizationMemberGithubLoginSerializer(serializers.Serializer):OpenApiParameter(name="search",type=OpenApiTypes.STR,- description="Match against member `first_name`, `last_name`, and `email`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, prefix-as-you-type) together, ordered exact-first; each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.",+ description="Match against member `first_name`, `last_name`, and `email`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.",),],),@@ -249,6 +250,9 @@ class OrganizationMemberViewSet(return queryset+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+def perform_destroy(self, instance: Model):instance = cast(OrganizationMembership, instance)requesting_user = cast(User, self.request.user)diff --git a/posthog/api/shared.py b/posthog/api/shared.pyindex 6afeb0eda144..65ec66b566c8 100644--- a/posthog/api/shared.py+++ b/posthog/api/shared.py@@ -35,8 +35,8 @@ class SearchMatchTypeSerializerMixin(serializers.Serializer):read_only=True,help_text=("How this row matched the `search` query parameter: `exact` (the term is a "- "case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match "- "only). Results are ordered exact-first. Null when the list is not filtered by `search`."+ "case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, "+ "returned only when no exact match exists). Null when the list is not filtered by `search`."),)diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.pyindex f1f46254ab42..31341ab5dfa4 100644--- a/posthog/api/test/dashboards/test_dashboard.py+++ b/posthog/api/test/dashboards/test_dashboard.py@@ -281,6 +281,17 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):assert result_ids == [target_id]+ def test_list_filter_by_search_decides_match_tier_after_tag_filter(self):+ self.dashboard_api.create_dashboard({"name": "sales dashboard", "tags": ["marketing"]})+ similar_id, _ = self.dashboard_api.create_dashboard({"name": "dahsboard metrics", "tags": ["finance"]})++ response = self.dashboard_api.list_dashboards(query_params={"search": "dashboard", "tags": ["finance"]})+ results = response["results"]++ assert [(d["id"], d["search_match_type"]) for d in results] == [(similar_id, "similar")], (+ "an exact match removed by the tag filter must not suppress the similar matches that survive it"+ )+@parameterized.expand([("whitespace-only", " "),@@ -358,7 +369,7 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):)assert all(d["name"] != "Totally unrelated" for d in results)- def test_list_filter_by_search_returns_exact_first_with_match_type(self):+ def test_list_filter_by_search_hides_similar_matches_when_exact_matches_exist(self):for name in ("dashboard overview", "sales dashboard", "dahsboard metrics", "Engineering metrics"):self.dashboard_api.create_dashboard({"name": name})@@ -369,11 +380,7 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):assert match_type_by_name == {"dashboard overview": "exact","sales dashboard": "exact",- "dahsboard metrics": "similar",- }-- match_types = [d["search_match_type"] for d in results]- assert match_types == ["exact", "exact", "similar"], f"exact matches must rank first, got {match_types}"+ }, "similar matches must be hidden when exact matches exist"def test_list_filter_by_search_match_type_absent_without_search(self):self.dashboard_api.create_dashboard({"name": "Alpha"})diff --git a/posthog/api/test/test_cohort.py b/posthog/api/test/test_cohort.pyindex cfba120dd7cf..9578970e1aeb 100644--- a/posthog/api/test/test_cohort.py+++ b/posthog/api/test/test_cohort.py@@ -1613,17 +1613,19 @@ [email protected],assert response["results"] == []- def test_cohort_list_search_orders_exact_before_similar_and_labels_match_type(self):+ def test_cohort_list_search_hides_similar_when_exact_exists_but_falls_back_when_none(self):exact = Cohort.objects.create(team=self.team, name="marketing", created_by=self.user)similar = Cohort.objects.create(team=self.team, name="markteing", created_by=self.user)- response = self.client.get(f"/api/projects/{self.team.id}/cohorts?search=marketing").json()- results = response["results"]- by_id = {c["id"]: c for c in results}+ with_exact = self.client.get(f"/api/projects/{self.team.id}/cohorts?search=marketing").json()["results"]+ assert [c["id"] for c in with_exact] == [exact.id], "similar matches must be hidden when exact matches exist"+ assert with_exact[0]["search_match_type"] == "exact"- assert [c["id"] for c in results][:2] == [exact.id, similar.id]- assert by_id[exact.id]["search_match_type"] == "exact"- assert by_id[similar.id]["search_match_type"] == "similar"+ # Delete the exact match; the fuzzy-only match must now surface as the fallback.+ exact.delete()+ without_exact = self.client.get(f"/api/projects/{self.team.id}/cohorts?search=marketing").json()["results"]+ assert [c["id"] for c in without_exact] == [similar.id]+ assert without_exact[0]["search_match_type"] == "similar"def test_cohort_list_omits_search_match_type_when_not_searching(self):Cohort.objects.create(team=self.team, name="Power users", created_by=self.user)diff --git a/posthog/api/test/test_organization_members.py b/posthog/api/test/test_organization_members.pyindex ce49f912541b..886dd9058535 100644--- a/posthog/api/test/test_organization_members.py+++ b/posthog/api/test/test_organization_members.py@@ -569,7 +569,7 @@ class TestOrganizationMembersAPI(APIBaseTest, QueryMatchingTest):)assert "[email protected]" not in match_type_by_email- def test_list_organization_members_search_returns_exact_first_with_match_type(self):+ def test_list_organization_members_search_hides_similar_matches_when_exact_matches_exist(self):User.objects.create_and_join(self.organization, "[email protected]", None, first_name="Marketing", last_name="Director")@@ -583,15 +583,11 @@ class TestOrganizationMembersAPI(APIBaseTest, QueryMatchingTest):response = self.client.get("/api/organizations/@current/members/?search=marketing")assert response.status_code == status.HTTP_200_OKresults = response.json()["results"]- emails = [r["user"]["email"] for r in results]- match_type_by_email = {r["user"]["email"]: r["search_match_type"] for r in results}- assert match_type_by_email.get("[email protected]") == "exact"- assert match_type_by_email.get("[email protected]") == "similar"- assert "[email protected]" not in emails- assert emails.index("[email protected]") < emails.index("[email protected]"), (- f"exact match must rank ahead of the fuzzy-only match, got {emails}"+ assert [r["user"]["email"] for r in results] == ["[email protected]"], (+ "similar matches must be hidden when exact matches exist")+ assert results[0]["search_match_type"] == "exact"def test_list_organization_members_search_match_type_absent_without_search(self):User.objects.create_and_join(self.organization, "[email protected]", None)diff --git a/posthog/helpers/trigram_search.py b/posthog/helpers/trigram_search.pyindex 4cf38183243f..a1fb139ffb0e 100644--- a/posthog/helpers/trigram_search.py+++ b/posthog/helpers/trigram_search.py@@ -2,7 +2,7 @@ from dataclasses import dataclassfrom typing import Anyfrom django.contrib.postgres.search import TrigramSimilarity, TrigramWordSimilarity-from django.db.models import Case, F, IntegerField, Q, QuerySet, Value, When+from django.db.models import Case, Exists, F, IntegerField, Q, QuerySet, Value, Whenfrom django.db.models.functions import Coalescefrom opentelemetry import trace@@ -81,17 +81,22 @@ def apply_trigram_search(extra_exact_q: Q | None = None,tiebreakers: tuple[str, ...] = (),) -> QuerySet:- """Apply trigram + literal-substring search across `fields`, then order exact-first.+ """Apply trigram + literal-substring search across `fields`, returning both match tiers.Two predicates select the rows. The literal `icontains` predicate (`exact_q`) catchestokens dense with non-alphanumerics — emails, UUIDs, dotted identifiers — where pg_trgmsplits at punctuation and scores below threshold. The trigram word-similarity predicate(`similar_q`) catches typos and prefix-as-you-type. A row matching `exact_q` is flagged- `_is_exact=1` and sorts ahead of fuzzy-only matches via the leading `-_is_exact` order key.+ `_is_exact=1`.- Within each exactness tier, `_search_score` ranks rows by each field's weighted word- similarity (plus full-string similarity where `include_full` is set). `tiebreakers` are- appended after the score (e.g. `-pinned`, `name`).+ Callers must pair this with `drop_similar_when_exact_exists` applied as the final filter+ on the queryset — that is what implements the "exact matches only, unless there are none"+ response contract. The tier decision lives there, not here, because it has to see the+ fully filtered row set (see that function's docstring).++ `_search_score` ranks rows by each field's weighted word similarity (plus full-string+ similarity where `include_full` is set). `tiebreakers` are appended after the score+ (e.g. `-pinned`, `name`).`extra_exact_q` OR's caller-supplied predicates into the exact tier — for structuredfields that don't fit trigram (a commit-SHA prefix, an exact numeric id). Rows matched@@ -140,17 +145,30 @@ def apply_trigram_search(component = component + F(f"_full_{f.key}")search_score = component if search_score is None else search_score + component- result = (- queryset.annotate(**word_annotations)- .annotate(- _is_exact=Case(When(exact_q, then=Value(1)), default=Value(0), output_field=IntegerField()),- _search_score=search_score,- )- .filter(exact_q | similar_q)- .order_by("-_is_exact", "-_search_score", *tiebreakers)+ annotated = queryset.annotate(**word_annotations).annotate(+ _is_exact=Case(When(exact_q, then=Value(1)), default=Value(0), output_field=IntegerField()),+ _search_score=search_score,)+ result = annotated.filter(exact_q | similar_q)if include_tag_search:result = result.distinct()- return result+ return result.order_by("-_search_score", *tiebreakers)+++def drop_similar_when_exact_exists(queryset: QuerySet) -> QuerySet:+ """Keep only exact matches when any exist; otherwise keep the similar matches, so a+ typo'd query still finds something. Without this, a caller re-sort (e.g. by+ last-modified) fills the visible area with similar matches and buries the exact hits.++ Must be the final filter on a searched queryset — the "any exact match?" probe is an+ EXISTS subquery over the queryset as passed in, so the tier decision sees exactly the+ rows the response will draw from. Applied any earlier, a subsequent filter could remove+ every exact match and the response would be empty despite surviving similar matches.++ No-op when the queryset was not searched (no `_is_exact` annotation)."""+ if "_is_exact" not in queryset.query.annotations:+ return queryset+ exact_matches = queryset.order_by().filter(_is_exact=1).values("pk")+ return queryset.filter(Q(_is_exact=1) | ~Exists(exact_matches))diff --git a/products/alerts/backend/api/alert.py b/products/alerts/backend/api/alert.pyindex 21527aed8f5b..e13f54dbc27c 100644--- a/products/alerts/backend/api/alert.py+++ b/products/alerts/backend/api/alert.py@@ -32,7 +32,12 @@ from posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.scoped_related_fields import TeamScopedPrimaryKeyRelatedFieldfrom posthog.api.shared import SearchMatchTypeSerializerMixin, UserBasicSerializerfrom posthog.event_usage import get_request_analytics_properties-from posthog.helpers.trigram_search import MAX_SEARCH_LENGTH, NAME_FIELD, apply_trigram_search+from posthog.helpers.trigram_search import (+ MAX_SEARCH_LENGTH,+ NAME_FIELD,+ apply_trigram_search,+ drop_similar_when_exact_exists,+)from posthog.models import Userfrom posthog.resource_limits import LimitKey, check_count_limitfrom posthog.schema_migrations.upgrade_manager import upgrade_query@@ -912,6 +917,9 @@ class AlertViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):return queryset+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+@staticmethoddef _apply_search(queryset: QuerySet, search: str) -> QuerySet:return apply_trigram_search(diff --git a/products/alerts/backend/api/test/test_alert.py b/products/alerts/backend/api/test/test_alert.pyindex 7f84e5aaf882..b65c4b475fa9 100644--- a/products/alerts/backend/api/test/test_alert.py+++ b/products/alerts/backend/api/test/test_alert.py@@ -1720,7 +1720,7 @@ class TestAlertListFilters(APIBaseTest):)assert all(a["name"] != "Totally unrelated" for a in results)- def test_list_filter_by_search_returns_exact_first_with_match_type(self) -> None:+ def test_list_filter_by_search_hides_similar_matches_when_exact_matches_exist(self) -> None:for name in ("revenue spike", "spike in revenue", "reveneu drop", "Unrelated alert"):self._create_alert(name)@@ -1731,11 +1731,7 @@ class TestAlertListFilters(APIBaseTest):assert match_type_by_name == {"revenue spike": "exact","spike in revenue": "exact",- "reveneu drop": "similar",- }-- match_types = [a["search_match_type"] for a in results]- assert match_types == ["exact", "exact", "similar"], f"exact matches must rank first, got {match_types}"+ }, "similar matches must be hidden when exact matches exist"def test_list_filter_by_search_match_type_absent_without_search(self) -> None:self._create_alert("Revenue spike")diff --git a/products/alerts/frontend/generated/api.schemas.ts b/products/alerts/frontend/generated/api.schemas.tsindex f6d7261abab7..ec76a152965b 100644--- a/products/alerts/frontend/generated/api.schemas.ts+++ b/products/alerts/frontend/generated/api.schemas.ts@@ -557,7 +557,7 @@ export interface AlertApi {* * `notify` - Notify* * `suppress` - Suppress */investigation_inconclusive_action?: InvestigationInconclusiveActionEnumApi- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -639,7 +639,7 @@ export interface PatchedAlertApi {* * `notify` - Notify* * `suppress` - Suppress */investigation_inconclusive_action?: InvestigationInconclusiveActionEnumApi- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnumApi | null}diff --git a/products/cdp/backend/api/hog_function.py b/products/cdp/backend/api/hog_function.pyindex baa25b84317d..1a963a51de69 100644--- a/products/cdp/backend/api/hog_function.py+++ b/products/cdp/backend/api/hog_function.py@@ -35,7 +35,13 @@ from posthog.cdp.validation import ()from posthog.exceptions_capture import capture_exceptionfrom posthog.helpers.impersonation import is_impersonated-from posthog.helpers.trigram_search import DESCRIPTION_FIELD, MAX_SEARCH_LENGTH, NAME_FIELD, apply_trigram_search+from posthog.helpers.trigram_search import (+ DESCRIPTION_FIELD,+ MAX_SEARCH_LENGTH,+ NAME_FIELD,+ apply_trigram_search,+ drop_similar_when_exact_exists,+)from posthog.models import Teamfrom posthog.models.activity_logging.activity_log import Change, Detail, log_activityfrom posthog.plugins.plugin_server_api import create_hog_invocation_test, rerun_hog_invocations@@ -604,6 +610,9 @@ class HogFunctionViewSet(return queryset+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+@action(detail=False, methods=["GET"])def icons(self, request: Request, *args, **kwargs):query = request.GET.get("query")diff --git a/products/cdp/backend/api/test/test_hog_function.py b/products/cdp/backend/api/test/test_hog_function.pyindex 30e4ddd9fd6f..7b1638481e56 100644--- a/products/cdp/backend/api/test/test_hog_function.py+++ b/products/cdp/backend/api/test/test_hog_function.py@@ -1925,7 +1925,7 @@ class TestHogFunctionAPI(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):)assert all(r["name"] != "Totally unrelated" for r in results)- def test_list_filter_by_search_returns_exact_first_with_match_type(self):+ def test_list_filter_by_search_hides_similar_matches_when_exact_matches_exist(self):for name in ("slack notification", "notification slack", "slcak metrics", "Engineering metrics"):HogFunction.objects.create(team=self.team, name=name, type="destination", hog="return event")@@ -1937,11 +1937,19 @@ class TestHogFunctionAPI(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):assert match_type_by_name == {"slack notification": "exact","notification slack": "exact",- "slcak metrics": "similar",- }+ }, "similar matches must be hidden when exact matches exist"++ def test_list_filter_by_search_decides_match_tier_after_type_filter(self):+ HogFunction.objects.create(team=self.team, name="slack notification", type="destination", hog="return event")+ HogFunction.objects.create(team=self.team, name="slcak transform", type="transformation", hog="return event")++ response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?search=slack&type=transformation")+ assert response.status_code == status.HTTP_200_OK+ results = response.json()["results"]- match_types = [r["search_match_type"] for r in results]- assert match_types == ["exact", "exact", "similar"], f"exact matches must rank first, got {match_types}"+ assert [(r["name"], r["search_match_type"]) for r in results] == [("slcak transform", "similar")], (+ "an exact match removed by the type filter must not suppress the similar matches that survive it"+ )def test_list_filter_by_search_match_type_absent_without_search(self):HogFunction.objects.create(team=self.team, name="Alpha", type="destination", hog="return event")diff --git a/products/cdp/frontend/generated/api.schemas.ts b/products/cdp/frontend/generated/api.schemas.tsindex 7cf0f2b8dc31..641d534d380a 100644--- a/products/cdp/frontend/generated/api.schemas.ts+++ b/products/cdp/frontend/generated/api.schemas.ts@@ -195,7 +195,7 @@ export interface HogFunctionMinimalApi {readonly status: HogFunctionStatusApi | null/** @nullable */readonly execution_order: number | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -441,7 +441,7 @@ export interface HogFunctionApi {_create_in_folder?: string/** @nullable */readonly batch_export_id: string | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -518,7 +518,7 @@ export interface PatchedHogFunctionApi {_create_in_folder?: string/** @nullable */readonly batch_export_id?: string | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnumApi | null}diff --git a/products/cdp/frontend/generated/api.zod.ts b/products/cdp/frontend/generated/api.zod.tsindex 543941b476fc..a64571edc31c 100644--- a/products/cdp/frontend/generated/api.zod.ts+++ b/products/cdp/frontend/generated/api.zod.ts@@ -1407,7 +1407,7 @@ export const HogFunctionsInvocationsCreateBody = /* @__PURE__ */ zod.object({search_match_type: zod.union([zod.enum(['exact', 'similar']), zod.null()]).describe(- 'How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`.'+ 'How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`.'),}).describe('Full function configuration to test.'),diff --git a/products/cohorts/frontend/generated/api.schemas.ts b/products/cohorts/frontend/generated/api.schemas.tsindex b63b65c69998..570ede2220ba 100644--- a/products/cohorts/frontend/generated/api.schemas.ts+++ b/products/cohorts/frontend/generated/api.schemas.ts@@ -225,7 +225,7 @@ export interface CohortApi {* * `analytical` - analytical */cohort_type?: CohortTypeEnumApi | BlankEnumApi | nullreadonly experiment_set: readonly number[]- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null_create_in_folder?: string_create_static_person_ids?: string[]@@ -280,7 +280,7 @@ export interface PatchedCohortApi {* * `analytical` - analytical */cohort_type?: CohortTypeEnumApi | BlankEnumApi | nullreadonly experiment_set?: readonly number[]- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnumApi | null_create_in_folder?: string_create_static_person_ids?: string[]@@ -418,7 +418,7 @@ export type CohortsListParams = {*/offset?: number/**- * Optional. Match against cohort `name`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first then by relevance; each result's `search_match_type` is `exact` or `similar`. When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries return a 400 error.+ * Optional. Match against cohort `name`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Results are ordered by relevance. When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries return a 400 error.*/search?: string}diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.pyindex 96091ecfa53f..76dc13effbcc 100644--- a/products/dashboards/backend/api/dashboard.py+++ b/products/dashboards/backend/api/dashboard.py@@ -62,7 +62,13 @@ from posthog.event_usage import EventSource, get_event_source, report_user_actiofrom posthog.exceptions_capture import capture_exceptionfrom posthog.helpers import create_dashboard_from_templatefrom posthog.helpers.dashboard_templates import create_from_template, dashboard_template_from_creation_payload-from posthog.helpers.trigram_search import DESCRIPTION_FIELD, MAX_SEARCH_LENGTH, NAME_FIELD, apply_trigram_search+from posthog.helpers.trigram_search import (+ DESCRIPTION_FIELD,+ MAX_SEARCH_LENGTH,+ NAME_FIELD,+ apply_trigram_search,+ drop_similar_when_exact_exists,+)from posthog.models.file_system.constants import DEFAULT_SURFACE, surface_qfrom posthog.models.file_system.file_system import FileSystem, create_or_update_file, delete_file, join_path, split_pathfrom posthog.models.quick_filter import QuickFilter@@ -2042,12 +2048,12 @@ class DashboardSerializer(DashboardMetadataSerializer):OpenApiTypes.STR,location=OpenApiParameter.QUERY,description=(- "Optional. Match against dashboard `name`, `description`, and tag names. Returns "- "case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, "- "prefix-as-you-type) together, ordered exact-first, then pinned status, then name; each "- "result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered "- "by pinned status then alphabetical name. Capped at 200 characters; longer queries return a "- "400 error."+ "Optional. Match against dashboard `name`, `description`, and tag names. Returns exact "+ "(case-insensitive substring) matches only; if no exact match exists, returns similar "+ "(fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Results "+ "are then ordered by relevance, then pinned status, then name; each result's `search_match_type` is "+ "`exact` or `similar`. When omitted, dashboards are ordered by pinned status then "+ "alphabetical name. Capped at 200 characters; longer queries return a 400 error."),),OpenApiParameter(@@ -2112,7 +2118,7 @@ class DashboardsViewSet(if folder is not None:queryset = self._apply_folder_filter(queryset, folder)- return queryset+ return drop_similar_when_exact_exists(queryset)@staticmethoddef _apply_folder_filter(queryset: QuerySet, folder: str) -> QuerySet:diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex bfbff8eae671..f12b031eee5c 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -275,7 +275,7 @@ export interface DashboardBasicApi {/** @nullable */readonly last_refresh: string | nullreadonly team_id: number- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -8098,7 +8098,7 @@ export interface InsightApi {readonly alerts: readonly unknown[]/** @nullable */readonly last_viewed_at: string | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -9058,7 +9058,7 @@ export type DashboardsListParams = {*/offset?: number/**- * Optional. Match against dashboard `name`, `description`, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.+ * Optional. Match against dashboard `name`, `description`, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Results are then ordered by relevance, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.*/search?: string}diff --git a/products/platform_features/frontend/generated/api.schemas.ts b/products/platform_features/frontend/generated/api.schemas.tsindex d7243cb6bec3..5f2d7dfc4aa7 100644--- a/products/platform_features/frontend/generated/api.schemas.ts+++ b/products/platform_features/frontend/generated/api.schemas.ts@@ -316,7 +316,7 @@ export interface OrganizationMemberApi {readonly is_2fa_enabled: booleanreadonly has_social_auth: booleanreadonly last_login: string- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -338,7 +338,7 @@ export interface PatchedOrganizationMemberApi {readonly is_2fa_enabled?: booleanreadonly has_social_auth?: booleanreadonly last_login?: string- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnumApi | null}@@ -872,7 +872,7 @@ export type MembersListParams = {*/order?: string/**- * Match against member `first_name`, `last_name`, and `email`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, prefix-as-you-type) together, ordered exact-first; each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.+ * Match against member `first_name`, `last_name`, and `email`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.*/search?: string}diff --git a/products/product_analytics/backend/api/insight.py b/products/product_analytics/backend/api/insight.pyindex d2617203c89e..a514b517e579 100644--- a/products/product_analytics/backend/api/insight.py+++ b/products/product_analytics/backend/api/insight.py@@ -69,6 +69,7 @@ from posthog.helpers.trigram_search import (NAME_FIELD,TrigramSearchField,apply_trigram_search,+ drop_similar_when_exact_exists,)from posthog.hogql_queries.apply_dashboard_filters import (WRAPPER_NODE_KINDS,@@ -1342,9 +1343,9 @@ Background calculation can be tracked using the `query_status` response field.""name="search",type=OpenApiTypes.STR,description=(- "Search term matched across name, derived_name, description, and tag names. Returns case-insensitive "- "substring matches and fuzzy trigram matches together in one list, ordered exact-first; each "- "result's `search_match_type` is `exact` or `similar`."+ "Search term matched across name, derived_name, description, and tag names. Returns exact "+ "(case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy "+ "trigram) matches instead. Each result's `search_match_type` is `exact` or `similar`."),),OpenApiParameter(@@ -1591,6 +1592,9 @@ class InsightViewSet(return pk_matchreturn queryset.filter(short_id=lookup_value).first()+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+def order_queryset(self, queryset: QuerySet) -> QuerySet:order = self.request.GET.get("order", None)if not order:diff --git a/products/product_analytics/backend/api/test/test_insight.py b/products/product_analytics/backend/api/test/test_insight.pyindex 8ad4d0906f43..50eb504f59ca 100644--- a/products/product_analytics/backend/api/test/test_insight.py+++ b/products/product_analytics/backend/api/test/test_insight.py@@ -890,11 +890,13 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):"explicit order=-id should override relevance ranking and put newer insight first")- def test_list_filter_by_search_returns_union_exact_first_with_match_type(self):+ def test_list_filter_by_search_hides_similar_matches_when_exact_matches_exist(self):for name in ("dashboard overview", "sales dashboard", "dahsboard metrics", "Engineering metrics"):Insight.objects.create(name=name, team=self.team, filters={"events": [{"id": "$pageview"}]})- response = self.client.get(f"/api/projects/{self.team.id}/insights/?search=dashboard")+ # The frontend always sends order=-last_modified_at; the fix must hold under it, since+ # that re-sort is what buried exact matches beneath similar ones in the first place.+ response = self.client.get(f"/api/projects/{self.team.id}/insights/?search=dashboard&order=-last_modified_at")assert response.status_code == status.HTTP_200_OKresults = response.json()["results"]@@ -902,11 +904,7 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):assert match_type_by_name == {"dashboard overview": "exact","sales dashboard": "exact",- "dahsboard metrics": "similar",- }-- match_types = [r["search_match_type"] for r in results]- assert match_types == ["exact", "exact", "similar"], f"exact matches must rank first, got {match_types}"+ }, "similar matches must be hidden when exact matches exist"def test_list_filter_by_search_match_type_absent_without_search(self):Insight.objects.create(name="Alpha", team=self.team, filters={"events": [{"id": "$pageview"}]})diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex 4a1ba1d8b6d4..122d22ee4fb2 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -7522,7 +7522,7 @@ export interface InsightApi {readonly alerts: readonly unknown[]/** @nullable */readonly last_viewed_at: string | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -7642,7 +7642,7 @@ export interface PatchedInsightApi {readonly alerts?: readonly unknown[]/** @nullable */readonly last_viewed_at?: string | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnumApi | null}@@ -7829,7 +7829,7 @@ export interface TrendingInsightApi {readonly user_access_level: string | null/** @nullable */readonly last_viewed_at: string | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null/** Number of distinct viewers in the time window. Higher values indicate insights that more people in the project actively look at, which is a strong proxy for which insights matter. */readonly view_count: number@@ -7999,7 +7999,7 @@ export type InsightsListParams = {*/saved?: boolean/**- * Search term matched across name, derived_name, description, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches together in one list, ordered exact-first; each result's `search_match_type` is `exact` or `similar`.+ * Search term matched across name, derived_name, description, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: stringshort_id?: stringdiff --git a/products/product_tours/backend/api/product_tour.py b/products/product_tours/backend/api/product_tour.pyindex 3c2230f159b8..6e563c5b175f 100644--- a/products/product_tours/backend/api/product_tour.py+++ b/products/product_tours/backend/api/product_tour.py@@ -27,7 +27,13 @@ from posthog.constants import PRODUCT_TOUR_TARGETING_FLAG_PREFIXfrom posthog.event_usage import report_user_actionfrom posthog.exceptions import generate_exception_responsefrom posthog.helpers.impersonation import is_impersonated-from posthog.helpers.trigram_search import DESCRIPTION_FIELD, MAX_SEARCH_LENGTH, NAME_FIELD, apply_trigram_search+from posthog.helpers.trigram_search import (+ DESCRIPTION_FIELD,+ MAX_SEARCH_LENGTH,+ NAME_FIELD,+ apply_trigram_search,+ drop_similar_when_exact_exists,+)from posthog.models.activity_logging.activity_log import Detail, changes_between, log_activityfrom posthog.models.team.team import Teamfrom posthog.models.user import User@@ -749,7 +755,7 @@ class GenerateResponseSerializer(serializers.Serializer):OpenApiParameter(name="search",type=OpenApiTypes.STR,- description="Fuzzy match against product tour `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.",+ description="Match against product tour `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.",),],),@@ -808,6 +814,9 @@ class ProductTourViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewqueryset = self._apply_search(queryset, search)return queryset+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+def perform_destroy(self, instance: ProductTour) -> None:"""Hard delete the tour and clean up related resources."""from django.utils import timezonediff --git a/products/product_tours/backend/api/test/test_product_tour.py b/products/product_tours/backend/api/test/test_product_tour.pyindex 168df865ee78..2a5fe8a192a8 100644--- a/products/product_tours/backend/api/test/test_product_tour.py+++ b/products/product_tours/backend/api/test/test_product_tour.py@@ -380,7 +380,7 @@ class TestProductTour(APIBaseTest):)assert all(r["name"] != "Totally unrelated" for r in results)- def test_list_filter_by_search_returns_exact_first_with_match_type(self):+ def test_list_filter_by_search_hides_similar_matches_when_exact_matches_exist(self):for name in ("onboarding tour", "tour for onboarding", "onbarding flow", "Engineering tour"):ProductTour.objects.create(team=self.team, name=name, content={"steps": []})@@ -392,11 +392,7 @@ class TestProductTour(APIBaseTest):assert match_type_by_name == {"onboarding tour": "exact","tour for onboarding": "exact",- "onbarding flow": "similar",- }-- match_types = [r["search_match_type"] for r in results]- assert match_types == ["exact", "exact", "similar"], f"exact matches must rank first, got {match_types}"+ }, "similar matches must be hidden when exact matches exist"def test_list_filter_by_search_match_type_absent_without_search(self):ProductTour.objects.create(team=self.team, name="Alpha", content={"steps": []})diff --git a/products/product_tours/frontend/generated/api.schemas.ts b/products/product_tours/frontend/generated/api.schemas.tsindex 65b03ce77205..40865e2ea6f2 100644--- a/products/product_tours/frontend/generated/api.schemas.ts+++ b/products/product_tours/frontend/generated/api.schemas.ts@@ -159,7 +159,7 @@ export interface ProductTourApi {readonly created_by: UserBasicApireadonly updated_at: stringarchived?: boolean- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -277,7 +277,7 @@ export type ProductToursListParams = {*/offset?: number/**- * Fuzzy match against product tour `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.+ * Match against product tour `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: string}diff --git a/products/surveys/backend/api/survey.py b/products/surveys/backend/api/survey.pyindex c58d1d6ff8ed..9841335ef768 100644--- a/products/surveys/backend/api/survey.py+++ b/products/surveys/backend/api/survey.py@@ -49,7 +49,13 @@ from posthog.cloud_utils import is_cloudfrom posthog.constants import SURVEY_TARGETING_FLAG_PREFIX, AvailableFeaturefrom posthog.event_usage import report_user_actionfrom posthog.helpers.impersonation import is_impersonated-from posthog.helpers.trigram_search import DESCRIPTION_FIELD, MAX_SEARCH_LENGTH, NAME_FIELD, apply_trigram_search+from posthog.helpers.trigram_search import (+ DESCRIPTION_FIELD,+ MAX_SEARCH_LENGTH,+ NAME_FIELD,+ apply_trigram_search,+ drop_similar_when_exact_exists,+)from posthog.models.activity_logging.activity_log import Change, Detail, changes_between, load_activity, log_activityfrom posthog.models.activity_logging.activity_page import activity_page_responsefrom posthog.models.team.team import Team@@ -2047,7 +2053,7 @@ class SurveyFilterSet(FilterSet):OpenApiParameter(name="search",type=OpenApiTypes.STR,- description="Fuzzy match against survey `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.",+ description="Match against survey `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.",),],),@@ -2075,13 +2081,16 @@ class SurveyViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.raise serializers.ValidationError({"search": f"Search query must be {MAX_SEARCH_LENGTH} characters or fewer."})- # Search applies its own exact-first relevance ordering — don't override it.+ # Search applies its own relevance ordering — don't override it.queryset = self._apply_search(queryset, search)else:# Newest first — stable order for pagination and surfaces recent surveys first in pickers.queryset = queryset.order_by("-created_at")return queryset+ def filter_queryset(self, queryset: QuerySet) -> QuerySet:+ return drop_similar_when_exact_exists(super().filter_queryset(queryset))+@tracer.start_as_current_span("SurveyViewSet.list")def list(self, request: request.Request, *args: Any, **kwargs: Any) -> Response:response = super().list(request, *args, **kwargs)diff --git a/products/surveys/backend/api/test/test_survey.py b/products/surveys/backend/api/test/test_survey.pyindex 1e26c075fadf..de74e899c01b 100644--- a/products/surveys/backend/api/test/test_survey.py+++ b/products/surveys/backend/api/test/test_survey.py@@ -3580,7 +3580,7 @@ class TestSurvey(APIBaseTest):)assert all(r["name"] != "Totally unrelated" for r in results)- def test_list_filter_by_search_returns_exact_first_with_match_type(self):+ def test_list_filter_by_search_hides_similar_matches_when_exact_matches_exist(self):for name in ("feedback survey", "survey feedback", "feeback form", "Engineering survey"):Survey.objects.create(team=self.team, name=name, type="popover", questions=[])@@ -3592,11 +3592,7 @@ class TestSurvey(APIBaseTest):assert match_type_by_name == {"feedback survey": "exact","survey feedback": "exact",- "feeback form": "similar",- }-- match_types = [r["search_match_type"] for r in results]- assert match_types == ["exact", "exact", "similar"], f"exact matches must rank first, got {match_types}"+ }, "similar matches must be hidden when exact matches exist"def test_list_filter_by_search_match_type_absent_without_search(self):Survey.objects.create(team=self.team, name="Alpha", type="popover", questions=[])diff --git a/products/surveys/frontend/generated/api.schemas.ts b/products/surveys/frontend/generated/api.schemas.tsindex d64d69e4b6f2..273bb0ccc39d 100644--- a/products/surveys/frontend/generated/api.schemas.ts+++ b/products/surveys/frontend/generated/api.schemas.ts@@ -364,7 +364,7 @@ export interface SurveyApi {*/readonly user_access_level: string | nullform_content?: unknown- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnumApi | null}@@ -2154,7 +2154,7 @@ export type SurveysListParams = {*/offset?: number/**- * Fuzzy match against survey `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.+ * Match against survey `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: string/**diff --git a/products/visual_review/backend/logic.py b/products/visual_review/backend/logic.pyindex e87eabf117a0..1b48883b3a33 100644--- a/products/visual_review/backend/logic.py+++ b/products/visual_review/backend/logic.py@@ -34,7 +34,12 @@ if TYPE_CHECKING:from posthog.models.integration import GitHubIntegrationfrom posthog.egress.github.transport import GitHubRateLimitError-from posthog.helpers.trigram_search import TrigramSearchField, apply_trigram_search, normalize_search_term+from posthog.helpers.trigram_search import (+ TrigramSearchField,+ apply_trigram_search,+ drop_similar_when_exact_exists,+ normalize_search_term,+)from posthog.models.github_integration_base import GitHubIntegrationErrorfrom .classifier import SnapshotClassifier@@ -303,13 +308,15 @@ def list_runs_for_team(extra_exact_q = Q(commit_sha__istartswith=term)if term.isdigit():extra_exact_q |= Q(pr_number=int(term))- return apply_trigram_search(- qs,- term,- span_prefix="visual_review.runs.search",- fields=RUN_SEARCH_FIELDS,- extra_exact_q=extra_exact_q,- tiebreakers=("-created_at",),+ return drop_similar_when_exact_exists(+ apply_trigram_search(+ qs,+ term,+ span_prefix="visual_review.runs.search",+ fields=RUN_SEARCH_FIELDS,+ extra_exact_q=extra_exact_q,+ tiebreakers=("-created_at",),+ ))return qs.order_by("-created_at")diff --git a/products/visual_review/backend/presentation/serializers.py b/products/visual_review/backend/presentation/serializers.pyindex 19ae29d9f472..39708de438a1 100644--- a/products/visual_review/backend/presentation/serializers.py+++ b/products/visual_review/backend/presentation/serializers.py@@ -99,8 +99,8 @@ class RunSerializer(DataclassSerializer):help_text=("How this row matched the `search` query parameter: `exact` (the term is a ""case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR "- "number) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. "- "Null when the list is not filtered by `search`."+ "number) or `similar` (a fuzzy trigram match, returned only when no exact match "+ "exists). Null when the list is not filtered by `search`."),)diff --git a/products/visual_review/backend/tests/test_presentation.py b/products/visual_review/backend/tests/test_presentation.pyindex 684074b6b37e..a79bfd58a9d5 100644--- a/products/visual_review/backend/tests/test_presentation.py+++ b/products/visual_review/backend/tests/test_presentation.py@@ -575,12 +575,13 @@ class TestRepoRunsSearch(VisualReviewTeamScopedTestMixin, APIBaseTest):self.assertEqual(response.status_code, status.HTTP_200_OK)self.assertEqual(self._branches(response.json()), expected_branches)- def test_exact_matches_rank_before_fuzzy_and_set_match_type(self):+ def test_exact_matches_hide_fuzzy_matches_and_set_match_type(self):# "login" is a substring of feature/login (exact) and a fuzzy match for fix/logout (similar).+ # With an exact match present, the fuzzy-only match is suppressed.results = self.client.get(self._runs_url(search="login")).json()["results"]- self.assertEqual([run["branch"] for run in results], ["feature/login", "fix/logout"])- self.assertEqual([run["search_match_type"] for run in results], ["exact", "similar"])+ self.assertEqual([run["branch"] for run in results], ["feature/login"])+ self.assertEqual([run["search_match_type"] for run in results], ["exact"])def test_match_type_is_null_without_search(self):results = self.client.get(self._runs_url()).json()["results"]diff --git a/products/visual_review/frontend/generated/api.schemas.ts b/products/visual_review/frontend/generated/api.schemas.tsindex 5726a7bb6e7e..f5f76b68c68c 100644--- a/products/visual_review/frontend/generated/api.schemas.ts+++ b/products/visual_review/frontend/generated/api.schemas.ts@@ -174,7 +174,7 @@ export type RunApiMetadata = { [key: string]: unknown }export interface RunApi {approved_by?: UserBasicInfoApi | null- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR number) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`.+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR number) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`.** * `exact` - exact* * `similar` - similar */diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex b1cd271a10d1..66e6fa51cb25 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -7652,7 +7652,7 @@ export namespace Schemas {readonly alerts: readonly unknown[];/** @nullable */readonly last_viewed_at: string | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -9170,7 +9170,7 @@ export namespace Schemas {* * `notify` - Notify* * `suppress` - Suppress */investigation_inconclusive_action?: InvestigationInconclusiveActionEnum;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -13325,7 +13325,7 @@ export namespace Schemas {* * `analytical` - analytical */cohort_type?: CohortTypeEnum | BlankEnum | null;readonly experiment_set: readonly number[];- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;_create_in_folder?: string;_create_static_person_ids?: string[];@@ -14826,7 +14826,7 @@ export namespace Schemas {/** @nullable */readonly last_refresh: string | null;readonly team_id: number;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -24532,7 +24532,7 @@ export namespace Schemas {export interface Run {approved_by?: UserBasicInfo | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR number) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`.+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of branch/run type, a commit SHA prefix, or an exact PR number) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`.** * `exact` - exact* * `similar` - similar */@@ -26254,7 +26254,7 @@ export namespace Schemas {_create_in_folder?: string;/** @nullable */readonly batch_export_id: string | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -26307,7 +26307,7 @@ export namespace Schemas {readonly status: HogFunctionStatus | null;/** @nullable */readonly execution_order: number | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -31697,7 +31697,7 @@ export namespace Schemas {readonly is_2fa_enabled: boolean;readonly has_social_auth: boolean;readonly last_login: string;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -33212,7 +33212,7 @@ export namespace Schemas {readonly created_by: UserBasic;readonly updated_at: string;archived?: boolean;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -35063,7 +35063,7 @@ export namespace Schemas {*/readonly user_access_level: string | null;form_content?: unknown;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;}@@ -35978,7 +35978,7 @@ export namespace Schemas {readonly user_access_level: string | null;/** @nullable */readonly last_viewed_at: string | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type: SearchMatchTypeEnum | null;/** Number of distinct viewers in the time window. Higher values indicate insights that more people in the project actively look at, which is a strong proxy for which insights matter. */readonly view_count: number;@@ -37048,7 +37048,7 @@ export namespace Schemas {* * `notify` - Notify* * `suppress` - Suppress */investigation_inconclusive_action?: InvestigationInconclusiveActionEnum;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnum | null;}@@ -37273,7 +37273,7 @@ export namespace Schemas {* * `analytical` - analytical */cohort_type?: CohortTypeEnum | BlankEnum | null;readonly experiment_set?: readonly number[];- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnum | null;_create_in_folder?: string;_create_static_person_ids?: string[];@@ -39282,7 +39282,7 @@ export namespace Schemas {_create_in_folder?: string;/** @nullable */readonly batch_export_id?: string | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnum | null;}@@ -39461,7 +39461,7 @@ export namespace Schemas {readonly alerts?: readonly unknown[];/** @nullable */readonly last_viewed_at?: string | null;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnum | null;}@@ -40162,7 +40162,7 @@ export namespace Schemas {readonly is_2fa_enabled?: boolean;readonly has_social_auth?: boolean;readonly last_login?: string;- /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`. */+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */readonly search_match_type?: SearchMatchTypeEnum | null;}@@ -57318,7 +57318,7 @@ export namespace Schemas {*/offset?: number;/**- * Optional. Match against dashboard `name`, `description`, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.+ * Optional. Match against dashboard `name`, `description`, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Results are then ordered by relevance, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.*/search?: string;};@@ -59299,7 +59299,7 @@ export namespace Schemas {*/saved?: boolean;/**- * Search term matched across name, derived_name, description, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches together in one list, ordered exact-first; each result's `search_match_type` is `exact` or `similar`.+ * Search term matched across name, derived_name, description, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: string;short_id?: string;@@ -61919,7 +61919,7 @@ export namespace Schemas {*/order?: string;/**- * Match against member `first_name`, `last_name`, and `email`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, prefix-as-you-type) together, ordered exact-first; each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.+ * Match against member `first_name`, `last_name`, and `email`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.*/search?: string;};@@ -63107,7 +63107,7 @@ export namespace Schemas {*/offset?: number;/**- * Optional. Match against cohort `name`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first then by relevance; each result's `search_match_type` is `exact` or `similar`. When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries return a 400 error.+ * Optional. Match against cohort `name`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Results are ordered by relevance. When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries return a 400 error.*/search?: string;};@@ -63454,7 +63454,7 @@ export namespace Schemas {*/offset?: number;/**- * Optional. Match against dashboard `name`, `description`, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.+ * Optional. Match against dashboard `name`, `description`, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Results are then ordered by relevance, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.*/search?: string;};@@ -66257,7 +66257,7 @@ export namespace Schemas {*/saved?: boolean;/**- * Search term matched across name, derived_name, description, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches together in one list, ordered exact-first; each result's `search_match_type` is `exact` or `similar`.+ * Search term matched across name, derived_name, description, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: string;short_id?: string;@@ -68140,7 +68140,7 @@ export namespace Schemas {*/offset?: number;/**- * Fuzzy match against product tour `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.+ * Match against product tour `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: string;};@@ -68780,7 +68780,7 @@ export namespace Schemas {*/offset?: number;/**- * Fuzzy match against survey `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.+ * Match against survey `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.*/search?: string;/**diff --git a/services/mcp/src/generated/cdp_functions/api.ts b/services/mcp/src/generated/cdp_functions/api.tsindex 084a938d6302..a20712877bf7 100644--- a/services/mcp/src/generated/cdp_functions/api.ts+++ b/services/mcp/src/generated/cdp_functions/api.ts@@ -947,7 +947,7 @@ export const HogFunctionsInvocationsCreateBody = /* @__PURE__ */ zod.object({.union([zod.enum(['exact', 'similar']), zod.null()]).optional().describe(- 'How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`.'+ 'How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`.'),}).describe('Full function configuration to test.'),diff --git a/services/mcp/src/generated/cohorts/api.ts b/services/mcp/src/generated/cohorts/api.tsindex 642068cebc0b..053336133ef7 100644--- a/services/mcp/src/generated/cohorts/api.ts+++ b/services/mcp/src/generated/cohorts/api.ts@@ -35,7 +35,7 @@ export const CohortsListQueryParams = /* @__PURE__ */ zod.object({.string().optional().describe(- "Optional. Match against cohort `name`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first then by relevance; each result's `search_match_type` is `exact` or `similar`. When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries return a 400 error."+ "Optional. Match against cohort `name`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Results are ordered by relevance. When omitted, cohorts are ordered newest-first. Capped at 200 characters; longer queries return a 400 error."),})diff --git a/services/mcp/src/generated/dashboards/api.ts b/services/mcp/src/generated/dashboards/api.tsindex 34403deb5fdc..7e601ec14d02 100644--- a/services/mcp/src/generated/dashboards/api.ts+++ b/services/mcp/src/generated/dashboards/api.ts@@ -30,7 +30,7 @@ export const DashboardsListQueryParams = /* @__PURE__ */ zod.object({.string().optional().describe(- "Optional. Match against dashboard `name`, `description`, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error."+ "Optional. Match against dashboard `name`, `description`, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Results are then ordered by relevance, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error."),})diff --git a/services/mcp/src/generated/platform_features/api.ts b/services/mcp/src/generated/platform_features/api.tsindex 44e910343cbb..c13747a863ca 100644--- a/services/mcp/src/generated/platform_features/api.ts+++ b/services/mcp/src/generated/platform_features/api.ts@@ -33,7 +33,7 @@ export const MembersListQueryParams = /* @__PURE__ */ zod.object({.string().optional().describe(- "Match against member `first_name`, `last_name`, and `email`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, prefix-as-you-type) together, ordered exact-first; each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters."+ "Match against member `first_name`, `last_name`, and `email`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters."),})diff --git a/services/mcp/src/generated/product_analytics/api.ts b/services/mcp/src/generated/product_analytics/api.tsindex ea639a1c40a2..de4ba62f125a 100644--- a/services/mcp/src/generated/product_analytics/api.ts+++ b/services/mcp/src/generated/product_analytics/api.ts@@ -149,7 +149,7 @@ export const InsightsListQueryParams = /* @__PURE__ */ zod.object({.string().optional().describe(- "Search term matched across name, derived_name, description, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches together in one list, ordered exact-first; each result's `search_match_type` is `exact` or `similar`."+ "Search term matched across name, derived_name, description, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram) matches instead. Each result's `search_match_type` is `exact` or `similar`."),short_id: zod.string().optional(),tags: zoddiff --git a/services/mcp/src/generated/surveys/api.ts b/services/mcp/src/generated/surveys/api.tsindex 7298a00db6b2..235ccef49944 100644--- a/services/mcp/src/generated/surveys/api.ts+++ b/services/mcp/src/generated/surveys/api.ts@@ -25,7 +25,7 @@ export const SurveysListQueryParams = /* @__PURE__ */ zod.object({.string().optional().describe(- 'Fuzzy match against survey `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.'+ "Match against survey `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`."),type: zod.enum(['api', 'external_survey', 'popover', 'widget'])diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-invocations-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-invocations-create.jsonindex 205d07a2a4dc..5f5b919b276c 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-invocations-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/cdp-functions-invocations-create.json@@ -592,7 +592,7 @@"type": "null"}],- "description": "How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match only). Results are ordered exact-first. Null when the list is not filtered by `search`."+ "description": "How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`."},"status": {"anyOf": [diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.jsonindex 7d67cdcf45cc..20d5963cd86f 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboards-get-all.json@@ -14,7 +14,7 @@"type": "number"},"search": {- "description": "Optional. Match against dashboard `name`, `description`, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches (typos, transpositions, prefix-as-you-type) together, ordered exact-first, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.",+ "description": "Optional. Match against dashboard `name`, `description`, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, transpositions, prefix-as-you-type) matches instead. Results are then ordered by relevance, then pinned status, then name; each result's `search_match_type` is `exact` or `similar`. When omitted, dashboards are ordered by pinned status then alphabetical name. Capped at 200 characters; longer queries return a 400 error.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/insights-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/insights-list.jsonindex 372766afce8d..494569e6de0d 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/insights-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/insights-list.json@@ -55,7 +55,7 @@"type": "boolean"},"search": {- "description": "Search term matched across name, derived_name, description, and tag names. Returns case-insensitive substring matches and fuzzy trigram matches together in one list, ordered exact-first; each result's `search_match_type` is `exact` or `similar`.",+ "description": "Search term matched across name, derived_name, description, and tag names. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram) matches instead. Each result's `search_match_type` is `exact` or `similar`.","type": "string"},"short_id": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/org-members-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/org-members-list.jsonindex 4dc5745fe403..5f9cade10e12 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/org-members-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/org-members-list.json@@ -14,7 +14,7 @@"type": "string"},"search": {- "description": "Match against member `first_name`, `last_name`, and `email`. Returns case-insensitive substring matches and fuzzy trigram matches (typos, prefix-as-you-type) together, ordered exact-first; each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.",+ "description": "Match against member `first_name`, `last_name`, and `email`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`. Capped at 200 characters.","type": "string"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/surveys-get-all.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/surveys-get-all.jsonindex 631ad2fb0868..ec5dced0cc66 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/surveys-get-all.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/surveys-get-all.json@@ -20,7 +20,7 @@"type": "number"},"search": {- "description": "Fuzzy match against survey `name` and `description` using Postgres trigram word similarity. Supports typos and prefix-as-you-type.",+ "description": "Match against survey `name` and `description`. Returns exact (case-insensitive substring) matches only; if no exact match exists, returns similar (fuzzy trigram — typos, prefix-as-you-type) matches instead. Each result's `search_match_type` is `exact` or `similar`.","type": "string"},"type": {