Skip to content

Commit

Permalink
Migrate to new general search index logic (#52909)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori authored Nov 21, 2024
1 parent 656040f commit 11e025c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
3 changes: 3 additions & 0 deletions src/search/lib/elasticsearch-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -79,17 +74,8 @@ export function getSearchFromRequestParams<Type extends SearchTypes>(

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 }
Expand Down
12 changes: 0 additions & 12 deletions src/search/lib/search-request-params/search-params-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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',
Expand Down
8 changes: 7 additions & 1 deletion src/search/scripts/scrape/lib/search-index-records.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
}
Expand Down

0 comments on commit 11e025c

Please sign in to comment.