Fix: Exclude legacy docs from kb search and vice versa (#4833)

When you're searching in KB (v1.0) you don't really want the results
from docs and vice versa. There may be a better way to do this on
Algolia's side, but this is an easy fix for now.
This commit is contained in:
Mark Percival
2024-05-01 00:10:10 -04:00
committed by GitHub
parent 4dc656c90a
commit cb37e4aaf4
2 changed files with 24 additions and 0 deletions

View File

@@ -2,6 +2,9 @@ import { DocSearch } from "@docsearch/react";
import "@docsearch/css";
export default function SearchForm() {
// Keep /docs search in /docs (pre-1.0), and exclude /kb (>= 1.0)
const excludePathRegex = new RegExp(/^\/kb/)
return (
<div className="pb-3 -ml-1 flex justify-start border-b border-neutral-200 ">
<DocSearch
@@ -9,6 +12,15 @@ export default function SearchForm() {
appId="XXPZ9QVGFB"
apiKey="66664e8765e1645ea0b500acebb0b0c2"
indexName="firezone"
transformItems={(items) => {
return items.filter((item) => {
if (item.url) {
const pathname = (new URL(item.url)).pathname
if (pathname.match(excludePathRegex)) return false
}
return true
})
}}
/>
</div>
);

View File

@@ -2,6 +2,9 @@ import { DocSearch } from "@docsearch/react";
import "@docsearch/css";
export default function SearchForm() {
// Keep /kb search in /kb (>= v1.0), and exclude /docs (pre-1.0)
const excludePathRegex = new RegExp(/^\/docs/)
return (
<div className="pb-3 -ml-1 flex justify-start border-b border-neutral-200 ">
<DocSearch
@@ -9,6 +12,15 @@ export default function SearchForm() {
appId="XXPZ9QVGFB"
apiKey="66664e8765e1645ea0b500acebb0b0c2"
indexName="firezone"
transformItems={(items) => {
return items.filter((item) => {
if (item.url) {
const pathname = (new URL(item.url)).pathname
if (pathname.match(excludePathRegex)) return false
}
return true
})
}}
/>
</div>
);