Skip to content

: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.

fix(data-warehouse): retry a multi-word source search word by word (#103000)

Tom Owersce574d3bca87
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts
index fea52c15f510..4e4a674a57ba 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/sourceCatalogLogic.ts
@@ -171,6 +171,29 @@ export type sourceCatalogLogicType = MakeLogicType<
sourceCatalogLogicMeta
>
+// Fuse matches the whole search term as one pattern, so an extra word buries a term that would
+// match on its own: "csv" finds every file-storage connector, "csv files" finds nothing. Retry the
+// individual words when the whole term matches nothing, ranking an item by how many words it
+// matches, so a term that already works keeps its relevance order untouched.
+function searchCatalog(catalogFuse: Fuse, term: string): CatalogItem[] {
+ const whole = catalogFuse.search(term).map((r) => r.item)
+ // Capped: the retry costs one index lookup per word and runs on every keystroke.
+ const words = term
+ .split(/\s+/)
+ .filter((word) => word.length > 1)
+ .slice(0, 5)
+ if (whole.length > 0 || words.length < 2) {
+ return whole
+ }
+ const matchCounts = new Map<CatalogItem, number>()
+ for (const word of words) {
+ for (const { item } of catalogFuse.search(word)) {
+ matchCounts.set(item, (matchCounts.get(item) ?? 0) + 1)
+ }
+ }
+ return [...matchCounts.keys()].sort((a, b) => (matchCounts.get(b) ?? 0) - (matchCounts.get(a) ?? 0))
+}
+
export const sourceCatalogLogic = kea<sourceCatalogLogicType>([
path(['products', 'dataWarehouse', 'sourceCatalogLogic']),
props({} as SourceCatalogLogicProps),
@@ -355,7 +378,7 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([
selectedCategory: SourceCategoryFilter
): CatalogItem[] => {
const trimmed = search.trim()
- const base = trimmed ? catalogFuse.search(trimmed).map((r) => r.item) : catalogItems
+ const base = trimmed ? searchCatalog(catalogFuse, trimmed) : catalogItems
const filtered =
selectedCategory === ALL_SOURCES_CATEGORY
? base
@@ -399,9 +422,9 @@ export const sourceCatalogLogic = kea<sourceCatalogLogicType>([
if (!trimmed || selectedCategory === ALL_SOURCES_CATEGORY) {
return false
}
- return catalogFuse
- .search(trimmed)
- .some((r) => r.item.status !== 'coming_soon' && r.item.category !== selectedCategory)
+ return searchCatalog(catalogFuse, trimmed).some(
+ (item) => item.status !== 'coming_soon' && item.category !== selectedCategory
+ )
},
],
}),
diff --git a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts
index f3b359344e29..7e138265dfc6 100644
--- a/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts
+++ b/products/data_warehouse/frontend/scenes/NewSourceScene/tests/sourceCatalogLogic.test.ts
@@ -123,6 +123,30 @@ describe('sourceCatalogLogic', () => {
expect(names).toContain('aws')
})
+ // Fuse matches the whole search term as one pattern, so one extra word buries a term that
+ // matches on its own: each of these returned nothing at all, which sent the user to "request
+ // a source" for connectors we already have.
+ it.each(['source files', 'parquet file storage', 'amazon s3 bucket'])(
+ 'retries a multi-word search word by word for "%s"',
+ (search) => {
+ const logic = sourceCatalogLogic()
+ logic.actions.setSearch(search)
+
+ expect(logic.values.filteredItems.some((item) => item.selfManaged)).toBe(true)
+ }
+ )
+
+ it('ranks a multi-word retry by how many words each source matches', () => {
+ const logic = sourceCatalogLogic()
+ logic.actions.setSearch('amazon gcs gcp')
+
+ // `google-cloud` matches "gcs" and "gcp"; `aws` only "amazon". The closer match must lead,
+ // even though the first word found `aws` and word order alone would keep it first.
+ const names = logic.values.filteredItems.map((item) => item.name)
+ expect(names).toContain('aws')
+ expect(names.indexOf('google-cloud')).toBeLessThan(names.indexOf('aws'))
+ })
+
it('flags a cross-category match when a filtered search only hits another category', () => {
const logic = sourceCatalogLogic()
logic.actions.setSelectedCategory('Sales')