Skip to content

Commit

Permalink
fix: implement robust filtering for invalid search results
Browse files Browse the repository at this point in the history
Co-Authored-By: sam@knock.app <sam@knock.app>
  • Loading branch information
devin-ai-integration[bot] and samseely committed Feb 27, 2025
1 parent 19f72b8 commit d8f720c
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions components/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,37 @@ const Autocomplete = () => {
transformResponse({ hits }) {
// Add the "Ask AI" item at the top of the results
// Filter out any empty items or items with invalid paths to prevent empty entries in the dropdown
const filteredHits = hits[0].filter(
(hit) => hit && hit.objectID && hit.path && !hit.path.includes("send-window-preferences")
);

// List of valid content directories based on the content structure
const validContentDirs = [
"concepts",
"designing-workflows",
"developer-tools",
"getting-started",
"guides",
"in-app-ui",
"integrations",
"manage-your-account",
"managing-recipients",
"preferences",
"sdks",
"send-notifications",
"reference",
];

const filteredHits = hits[0].filter((hit) => {
if (!hit || !hit.objectID || !hit.path) return false;

// Check if the path starts with any of the valid content directories
// or is exactly one of the valid directories
const path = hit.path as string;
return validContentDirs.some(
(dir) =>
path.startsWith(dir + "/") ||
path === dir ||
path.startsWith(dir + "#"),
);
});
return [askAiItem, ...filteredHits];
},
});
Expand Down

0 comments on commit d8f720c

Please sign in to comment.