diff --git a/README.md b/README.md index 49d8593..4b3bb5f 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,12 @@ The `.env` looks like: ```bash API_KEY="0000000000000000000164dbb81fbea0a98f09eae1ff2a51493cb3a633523891==" CLOUD_ID="Deployment_name:0000000000000000000365ff7535528e43b5c6793e840c2b2a0a38e1648c930f" -INDEX="index-name" -COREDEV_INDEX="coredev-index-name" ``` +### Indexes Configuration + +The application supports multiple Elasticsearch indexes. The configuration for these indexes can be found in [`src/config/config.ts`](/src/config/config.ts). To add or modify indexes, update the `INDEXES` object. + ## Installation ```bash diff --git a/src/components/explore/IndexSelector.tsx b/src/components/explore/IndexSelector.tsx index fcf259e..c9f84d5 100644 --- a/src/components/explore/IndexSelector.tsx +++ b/src/components/explore/IndexSelector.tsx @@ -1,18 +1,30 @@ import React from "react"; +import { INDEXES, IndexType } from "@/config/config"; -const IndexSelector = ({ selectedIndex, onIndexChange }) => { +interface IndexSelectorProps { + selectedIndex: IndexType; + onIndexChange: (index: IndexType) => void; +} + +const IndexSelector: React.FC = ({ + selectedIndex, + onIndexChange, +}) => { return (
); diff --git a/src/config/config.ts b/src/config/config.ts index efaa4f3..66d321e 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -14,3 +14,24 @@ export const TruncateLengthInChar = 300; export const TruncateLinkInChar = 50; export const aggregatorSize = 100; + +export const INDEXES = { + MAIN: { + id: "main", + label: "Main", + indexName: "bitcoin-search-august-23", + }, + CORE_DEV: { + id: "coredev", + label: "Core Dev", + indexName: "bitcoin-core-august-23", + }, +} as const; + +export type IndexType = (typeof INDEXES)[keyof typeof INDEXES]["id"]; + +export const getIndexConfig = (id: IndexType) => { + return ( + Object.values(INDEXES).find((index) => index.id === id) ?? INDEXES.MAIN + ); +}; diff --git a/src/pages/api/elasticSearchProxy/getDocumentContent.ts b/src/pages/api/elasticSearchProxy/getDocumentContent.ts index c8deea0..68bf4ee 100644 --- a/src/pages/api/elasticSearchProxy/getDocumentContent.ts +++ b/src/pages/api/elasticSearchProxy/getDocumentContent.ts @@ -1,5 +1,6 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { client } from "@/config/elasticsearch"; +import { getIndexConfig, IndexType } from "@/config/config"; export default async function handler( req: NextApiRequest, @@ -20,13 +21,12 @@ export default async function handler( }); } - // Select index based on parameter - const selectedIndex = - index === "coredev" ? process.env.COREDEV_INDEX : process.env.INDEX; + // Get the actual index name from our config + const indexConfig = getIndexConfig(index as IndexType); try { const result = await client.search({ - index: selectedIndex, + index: indexConfig.indexName, body: { // This query handles two different indexing patterns across our ES indexes: // - In index A: document's _id matches its content 'id' field diff --git a/src/pages/api/elasticSearchProxy/search.ts b/src/pages/api/elasticSearchProxy/search.ts index e9313f5..6f68c06 100644 --- a/src/pages/api/elasticSearchProxy/search.ts +++ b/src/pages/api/elasticSearchProxy/search.ts @@ -1,6 +1,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { client } from "@/config/elasticsearch"; import { buildQuery } from "@/utils/server/apiFunctions"; +import { getIndexConfig, IndexType } from "@/config/config"; export default async function handler( req: NextApiRequest, @@ -23,9 +24,8 @@ export default async function handler( index = "main", } = req.body; - // Select index based on parameter - const selectedIndex = - index === "coredev" ? process.env.COREDEV_INDEX : process.env.INDEX; + // Get the actual index name from our config + const indexConfig = getIndexConfig(index as IndexType); const from = page * size; let searchQuery = buildQuery({ @@ -38,9 +38,8 @@ export default async function handler( }); try { - // Call the search method const result = await client.search({ - index: selectedIndex, + index: indexConfig.indexName, ...searchQuery, }); diff --git a/src/pages/explore.tsx b/src/pages/explore.tsx index 54b65a7..4e04f65 100644 --- a/src/pages/explore.tsx +++ b/src/pages/explore.tsx @@ -5,6 +5,7 @@ import NavBar from "@/components/navBar/NavBar"; import Footer from "@/components/footer/Footer"; import { useExplore } from "@/hooks/useExplore"; import IndexSelector from "@/components/explore/IndexSelector"; +import { IndexType } from "@/config/config"; interface ExplorerField { key: string; @@ -29,7 +30,7 @@ const EXPLORER_CONFIGS: Record = { const ExplorePage = () => { const [activeType, setActiveType] = useState("sources"); const [expandedItem, setExpandedItem] = useState(null); - const [selectedIndex, setSelectedIndex] = useState("main"); + const [selectedIndex, setSelectedIndex] = useState("main"); const config = EXPLORER_CONFIGS[activeType]; const { data, isLoading, isError, error } = useExplore(