diff --git a/src/search/lib/elasticsearch-versions.ts b/src/search/lib/elasticsearch-versions.ts index 19dfd937d87c..d365ddda57a7 100644 --- a/src/search/lib/elasticsearch-versions.ts +++ b/src/search/lib/elasticsearch-versions.ts @@ -30,7 +30,10 @@ export const versionToIndexVersionMap: { [key: string]: string } = {} // For each potential input (from request query string, CLI, etc), map it to the appropriate index version for (const versionSource of Object.values(allVersions)) { if (versionSource.hasNumberedReleases) { + // Map version number to corresponding release, e.g. `3.14` -> `ghes-3.14` versionToIndexVersionMap[versionSource.currentRelease] = versionSource.miscVersionName + // Map full release name to corresponding release, e.g. `enterprise-server@3.14` -> `ghes-3.14` + versionToIndexVersionMap[versionSource.version] = versionSource.miscVersionName // Map shortname or plan, e.g. `ghes` or `enterprise-server` to the latest release, e.g. `ghes-3.14` if (versionSource.latestRelease === versionSource.currentRelease) { versionToIndexVersionMap[versionSource.plan] = versionSource.miscVersionName diff --git a/src/search/lib/search-request-params/get-search-from-request-params.ts b/src/search/lib/search-request-params/get-search-from-request-params.ts index 1ae3fd38ad85..af3fd98b0cf6 100644 --- a/src/search/lib/search-request-params/get-search-from-request-params.ts +++ b/src/search/lib/search-request-params/get-search-from-request-params.ts @@ -6,11 +6,6 @@ import { ValidationError, getSearchRequestParamsObject, } from '@/search/lib/search-request-params/search-params-objects' -import { - getGeneralSearchIndexVersion, - getGeneralSearchIndexPrefix, - isBeforeSearchIndexMigration, -} from '@/search/lib/helpers/old-version-logic' import type { ComputedSearchQueryParams, @@ -79,17 +74,8 @@ export function getSearchFromRequestParams( let indexName = '' if (!validationErrors.length) { - // generalSearch is the only type of search that uses the old index prefix logic, rather than the `getElasticSearchIndex` function logic - if (type === 'generalSearch' && isBeforeSearchIndexMigration()) { - indexName = `${getGeneralSearchIndexPrefix()}github-docs-${getGeneralSearchIndexVersion(searchParams.version)}-${searchParams.language}` - } else { - const getIndexResults = getElasticSearchIndex( - type, - searchParams.version, - searchParams.language, - ) - indexName = getIndexResults.indexName - } + const getIndexResults = getElasticSearchIndex(type, searchParams.version, searchParams.language) + indexName = getIndexResults.indexName } return { indexName, searchParams, validationErrors } diff --git a/src/search/lib/search-request-params/search-params-objects.ts b/src/search/lib/search-request-params/search-params-objects.ts index 76dfce35e61e..23478b88a7ba 100644 --- a/src/search/lib/search-request-params/search-params-objects.ts +++ b/src/search/lib/search-request-params/search-params-objects.ts @@ -6,8 +6,6 @@ import languages from '@/languages/lib/languages' import { allIndexVersionKeys, versionToIndexVersionMap } from '@/search/lib/elasticsearch-versions' import { SearchTypes } from '@/search/types' -import { versionAliases } from '@/search/lib/helpers/old-version-logic' -import { allVersions } from '@/versions/lib/all-versions' import type { SearchRequestQueryParams } from '@/search/lib/search-request-params/types' @@ -60,16 +58,6 @@ const SHARED_PARAMS_OBJ: SearchRequestQueryParams[] = [ const GENERAL_SEARCH_PARAMS_OBJ: SearchRequestQueryParams[] = [ ...SHARED_PARAMS_OBJ, { key: 'query' }, - // TODO: Overwrite with old version logic for now - { - key: 'version', - default_: 'dotcom', - validate: (v) => { - if (versionAliases[v] || allVersions[v]) return true - const valid = [...Object.keys(versionAliases), ...Object.keys(allVersions)] - throw new ValidationError(`'${v}' not in ${valid}`) - }, - }, { key: 'language', default_: 'en', validate: (v) => v in languages }, { key: 'size', diff --git a/src/search/scripts/scrape/lib/search-index-records.ts b/src/search/scripts/scrape/lib/search-index-records.ts index c4459ccdb88a..cc8d1a802c3f 100644 --- a/src/search/scripts/scrape/lib/search-index-records.ts +++ b/src/search/scripts/scrape/lib/search-index-records.ts @@ -1,4 +1,5 @@ import path from 'path' +import fsSync from 'fs' import fs from 'fs/promises' import assert from 'assert' import { isArray, isString } from 'lodash-es' @@ -15,8 +16,13 @@ export async function writeIndexRecords( const recordsObject = Object.fromEntries(records.map((record) => [record.objectID, record])) const content = JSON.stringify(recordsObject, undefined, 0) + // If the outDirectory doesn't exist, create it + if (!fsSync.existsSync(outDirectory)) { + await fs.mkdir(outDirectory, { recursive: true }) + } + const filePath = path.join(outDirectory, `${name}-records.json`) - await fs.writeFile(filePath, content) + await fs.writeFile(filePath, content, { flag: 'w' }) return filePath }