From 2f81bb007de1ae9d5795b3d04dea60b139197b67 Mon Sep 17 00:00:00 2001 From: PothieuG Date: Tue, 17 Mar 2026 08:10:30 +0100 Subject: [PATCH 1/4] Enhancing search by highligthing snippet search --- app/api/search/route.ts | 12 +++++++++++- app/search/client-page.tsx | 14 ++++++++++++++ components/RuleCard.tsx | 10 +++++++++- components/SearchBar.tsx | 9 +++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/api/search/route.ts b/app/api/search/route.ts index ef3420ac3..aaf3441a1 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -95,7 +95,17 @@ export async function POST(request: NextRequest) { } const client = algoliasearch(appId, apiKey); - const result = await client.search(requests); + + // Inject snippet and highlight settings so results include content snippets + const enrichedRequests = requests.map((req: any) => ({ + ...req, + attributesToSnippet: ["content:30"], + attributesToHighlight: ["title", "content"], + highlightPreTag: "", + highlightPostTag: "", + })); + + const result = await client.search(enrichedRequests); return NextResponse.json(result); } catch (error) { diff --git a/app/search/client-page.tsx b/app/search/client-page.tsx index b01b9bd69..87122d135 100644 --- a/app/search/client-page.tsx +++ b/app/search/client-page.tsx @@ -22,6 +22,15 @@ interface SearchResult { objectID: string; title: string; slug: string; + _snippetResult?: { + content?: { value: string; matchLevel: string }; + [key: string]: any; + }; + _highlightResult?: { + title?: { value: string; matchLevel: string }; + content?: { value: string; matchLevel: string }; + [key: string]: any; + }; [key: string]: any; } @@ -163,6 +172,11 @@ export default function RulesSearchClientPage({ ruleCount, latestRulesByUpdated lastUpdated={result.lastUpdated ?? result.created ?? null} index={index} authorUrl={getAuthorUrl(result)} + snippet={ + result._snippetResult?.content?.matchLevel !== "none" + ? result._snippetResult?.content?.value + : null + } /> ))} diff --git a/components/RuleCard.tsx b/components/RuleCard.tsx index d86b7ef2c..b862ef281 100644 --- a/components/RuleCard.tsx +++ b/components/RuleCard.tsx @@ -11,6 +11,7 @@ interface RuleCardProps { index?: number; authorUrl?: string | null; skeletonMeta?: boolean; + snippet?: string | null; } function isHttpUrl(value?: string | null) { @@ -18,7 +19,7 @@ function isHttpUrl(value?: string | null) { return /^https?:\/\//i.test(value.trim()); } -export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta }: RuleCardProps) { +export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta, snippet }: RuleCardProps) { const showLink = !skeletonMeta && isHttpUrl(authorUrl) && (lastUpdatedBy || "Unknown") !== "Unknown"; return ( @@ -31,6 +32,13 @@ export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, inde

{title}

+ {snippet && ( +

+ )} + {skeletonMeta ? (

diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx index 24ba59b5e..c07a57bcf 100644 --- a/components/SearchBar.tsx +++ b/components/SearchBar.tsx @@ -11,6 +11,15 @@ interface SearchResult { objectID: string; title: string; slug: string; + _snippetResult?: { + content?: { value: string; matchLevel: string }; + [key: string]: any; + }; + _highlightResult?: { + title?: { value: string; matchLevel: string }; + content?: { value: string; matchLevel: string }; + [key: string]: any; + }; [key: string]: any; } From 1367dd6207e3fce0588f8132c6ccfe7db6541e0d Mon Sep 17 00:00:00 2001 From: PothieuG Date: Tue, 24 Mar 2026 16:44:32 +0100 Subject: [PATCH 2/4] Adding the launch of the script in the pipeline # Conflicts: # .github/workflows/build-artifacts.yml --- .github/workflows/build-artifacts.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml index f65294d05..4ec3a7c34 100644 --- a/.github/workflows/build-artifacts.yml +++ b/.github/workflows/build-artifacts.yml @@ -636,6 +636,7 @@ jobs: NEXT_PUBLIC_GITHUB_REPO: ${{ vars.NEXT_PUBLIC_GITHUB_REPO }} run: pnpm tinacms search-index + - name: Install Algolia Python dependencies run: pip install pyyaml "algoliasearch>=3,<4" @@ -645,4 +646,14 @@ jobs: NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ inputs.NEXT_PUBLIC_ALGOLIA_APP_ID }} NEXT_PUBLIC_ALGOLIA_ADMIN_KEY: ${{ secrets.NEXT_PUBLIC_ALGOLIA_ADMIN_KEY }} NEXT_PUBLIC_ALGOLIA_INDEX_NAME: ${{ inputs.NEXT_PUBLIC_ALGOLIA_INDEX_NAME }} - run: python algolia_sync.py \ No newline at end of file + run: python algolia_sync.py + + - name: Patch rule body content in Algolia index + env: + NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ secrets.NEXT_PUBLIC_ALGOLIA_APP_ID }} + NEXT_PUBLIC_ALGOLIA_ADMIN_KEY: ${{ secrets.NEXT_PUBLIC_ALGOLIA_ADMIN_KEY }} + NEXT_PUBLIC_ALGOLIA_INDEX_NAME: ${{ secrets.NEXT_PUBLIC_ALGOLIA_INDEX_NAME }} + run: | + cd content/scripts/tina-migration/algolia-indexer + npm install + node update_algolia_index.js From ba9a9b481d05547849f0af27f1b5f3d9d5ee8310 Mon Sep 17 00:00:00 2001 From: PothieuG Date: Tue, 24 Mar 2026 16:56:14 +0100 Subject: [PATCH 3/4] Fix code snippet --- app/api/search/route.ts | 12 +----------- components/RuleCard.tsx | 10 +--------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/app/api/search/route.ts b/app/api/search/route.ts index aaf3441a1..ef3420ac3 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -95,17 +95,7 @@ export async function POST(request: NextRequest) { } const client = algoliasearch(appId, apiKey); - - // Inject snippet and highlight settings so results include content snippets - const enrichedRequests = requests.map((req: any) => ({ - ...req, - attributesToSnippet: ["content:30"], - attributesToHighlight: ["title", "content"], - highlightPreTag: "", - highlightPostTag: "", - })); - - const result = await client.search(enrichedRequests); + const result = await client.search(requests); return NextResponse.json(result); } catch (error) { diff --git a/components/RuleCard.tsx b/components/RuleCard.tsx index b862ef281..d86b7ef2c 100644 --- a/components/RuleCard.tsx +++ b/components/RuleCard.tsx @@ -11,7 +11,6 @@ interface RuleCardProps { index?: number; authorUrl?: string | null; skeletonMeta?: boolean; - snippet?: string | null; } function isHttpUrl(value?: string | null) { @@ -19,7 +18,7 @@ function isHttpUrl(value?: string | null) { return /^https?:\/\//i.test(value.trim()); } -export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta, snippet }: RuleCardProps) { +export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta }: RuleCardProps) { const showLink = !skeletonMeta && isHttpUrl(authorUrl) && (lastUpdatedBy || "Unknown") !== "Unknown"; return ( @@ -32,13 +31,6 @@ export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, inde

{title}

- {snippet && ( -

- )} - {skeletonMeta ? (

From c1133f8435e3ed3f1b9b70e03ded271796eff7f2 Mon Sep 17 00:00:00 2001 From: PothieuG Date: Tue, 24 Mar 2026 18:08:40 +0100 Subject: [PATCH 4/4] Fixing build by adding snippet in the interface --- components/RuleCard.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/RuleCard.tsx b/components/RuleCard.tsx index d86b7ef2c..bbd3f7ac4 100644 --- a/components/RuleCard.tsx +++ b/components/RuleCard.tsx @@ -11,6 +11,7 @@ interface RuleCardProps { index?: number; authorUrl?: string | null; skeletonMeta?: boolean; + snippet?: string | null; } function isHttpUrl(value?: string | null) { @@ -18,7 +19,7 @@ function isHttpUrl(value?: string | null) { return /^https?:\/\//i.test(value.trim()); } -export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta }: RuleCardProps) { +export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, index, authorUrl, skeletonMeta, snippet }: RuleCardProps) { const showLink = !skeletonMeta && isHttpUrl(authorUrl) && (lastUpdatedBy || "Unknown") !== "Unknown"; return ( @@ -31,6 +32,13 @@ export default function RuleCard({ title, slug, lastUpdatedBy, lastUpdated, inde

{title}

+ {snippet && ( +

+ )} + {skeletonMeta ? (