Skip to content

Commit d589b2b

Browse files
heiskrCopilot
andauthored
Use real index names in the analyze-text script (#64035)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bf5940de-658e-4a1a-bffa-3018fb78b138
1 parent 9d854cf commit d589b2b

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎src/search/scripts/analyze-text.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import chalk from 'chalk'
99
import dotenv from 'dotenv'
1010

1111
import { languageKeys } from '@/languages/lib/languages-server'
12+
import { getElasticSearchIndex } from '@/search/lib/elasticsearch-indexes'
1213
import { allVersions } from '@/versions/lib/all-versions'
1314

1415
import type { estypes } from '@elastic/elasticsearch'
@@ -110,10 +111,9 @@ async function main(opts: Options, textArgs: string[]): Promise<void> {
110111
}
111112

112113
const { indexPrefix } = opts
113-
const prefix = indexPrefix ? `${indexPrefix}_` : ''
114114

115115
for (const languageKey of languagesToAnalyze) {
116-
const indexName = `${prefix}github-docs-${versionKey}-${languageKey}`
116+
const indexName = getIndexName(versionKey, languageKey, indexPrefix)
117117
console.log(chalk.yellow(`Analyzing in ${chalk.bold(indexName)}`))
118118
await analyzeVersion(client, texts, indexName)
119119
}
@@ -138,6 +138,11 @@ export function getLanguagesToAnalyze({
138138
return ['en']
139139
}
140140

141+
// Matches the names the general search indexer creates.
142+
export function getIndexName(version: string, language: string, indexPrefix = ''): string {
143+
return getElasticSearchIndex('generalSearch', version, language, indexPrefix).indexName
144+
}
145+
141146
function safeUrlDisplay(url: string): string {
142147
const parsed = new URL(url)
143148
if (parsed.password) {

‎src/search/tests/analyze-text.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { describe, expect, test } from 'vitest'
1+
import { afterEach, describe, expect, test, vi } from 'vitest'
22

33
import { languageKeys } from '@/languages/lib/languages-server'
4-
import { getLanguagesToAnalyze } from '@/search/scripts/analyze-text'
4+
import { getIndexName, getLanguagesToAnalyze } from '@/search/scripts/analyze-text'
5+
import { allVersions } from '@/versions/lib/all-versions'
56

67
describe('getLanguagesToAnalyze', () => {
78
test('defaults to English', () => {
@@ -24,3 +25,29 @@ describe('getLanguagesToAnalyze', () => {
2425
)
2526
})
2627
})
28+
29+
describe('getIndexName', () => {
30+
afterEach(() => {
31+
vi.unstubAllEnvs()
32+
})
33+
34+
test('maps dotcom to the fpt general search index', () => {
35+
expect(getIndexName('dotcom', 'en')).toBe('tests_github-docs_general-search_fpt_en')
36+
})
37+
38+
test('uses the ghec general search index', () => {
39+
expect(getIndexName('ghec', 'en')).toBe('tests_github-docs_general-search_ghec_en')
40+
})
41+
42+
test('uses the release in GHES general search index names', () => {
43+
const ghes = Object.values(allVersions).find((info) => info.hasNumberedReleases)!
44+
const versionKey = `${ghes.miscBaseName}${ghes.currentRelease}`
45+
expect(getIndexName(versionKey, 'en')).toBe(`tests_github-docs_general-search_${versionKey}_en`)
46+
})
47+
48+
test('adds one underscore after the index prefix', () => {
49+
vi.stubEnv('NODE_ENV', 'development')
50+
expect(getIndexName('dotcom', 'en', 'tests')).toBe('tests_github-docs_general-search_fpt_en')
51+
expect(getIndexName('dotcom', 'en', 'tests_')).toBe('tests_github-docs_general-search_fpt_en')
52+
})
53+
})

0 commit comments

Comments
 (0)