MCPcopy Create free account
hub / github.com/github/docs / buildRecords

Function buildRecords

script/search/build-records.js:24–82  ·  view source on GitHub ↗
(
  indexName,
  indexablePages,
  pageVersion,
  languageCode,
  redirects,
  config = {}
)

Source from the content-addressed store, hash-verified

22const MIN_TIME = parseInt(process.env.BUILD_RECORDS_MIN_TIME || '5', 10)
23
24export default async function buildRecords(
25 indexName,
26 indexablePages,
27 pageVersion,
28 languageCode,
29 redirects,
30 config = {}
31) {
32 const { noMarkers } = config
33 console.log(`\n\nBuilding records for index '${indexName}' (${languages[languageCode].name})`)
34 const records = []
35 const pages = indexablePages
36 // exclude pages that are not in the current language
37 .filter((page) => page.languageCode === languageCode)
38 // exclude pages that don't have a permalink for the current product version
39 .filter((page) => page.permalinks.some((permalink) => permalink.pageVersion === pageVersion))
40
41 // Find the approve permalink for the given language and GitHub product variant (dotcom v enterprise)
42 const permalinks = pages
43 .map((page) => {
44 return page.permalinks.find((permalink) => {
45 return permalink.languageCode === languageCode && permalink.pageVersion === pageVersion
46 })
47 })
48 .map((permalink) => {
49 permalink.url = `http://localhost:${port}${permalink.href}`
50 return permalink
51 })
52
53 const popularPages = await getPopularPages(redirects)
54
55 console.log('indexable pages', indexablePages.length)
56 console.log('pages in index', pages.length)
57 console.log('permalinks in index', permalinks.length)
58 console.log(pageMarker, 'denotes pages')
59 console.log(recordMarker, 'denotes records derived from sections of pages')
60 console.log('popular page ratios', Object.keys(popularPages).length)
61
62 const hasPopularPages = Object.keys(popularPages).length > 0
63
64 const waiter = domwaiter(permalinks, { maxConcurrent: MAX_CONCURRENT, minTime: MIN_TIME })
65 .on('page', (page) => {
66 if (!noMarkers) process.stdout.write(pageMarker)
67 const newRecord = parsePageSectionsIntoRecords(page)
68 const pathArticle = page.relativePath.replace('/index.md', '').replace('.md', '')
69 const popularity = (hasPopularPages && popularPages[pathArticle]) || 0.0
70 newRecord.popularity = popularity
71 if (!noMarkers) process.stdout.write(recordMarker)
72 records.push(newRecord)
73 })
74 .on('error', (err) => {
75 console.error(err)
76 })
77
78 return eventToPromise(waiter, 'done').then(() => {
79 console.log('\nrecords in index: ', records.length)
80 return records
81 })

Callers 1

syncSearchIndexesFunction · 0.85

Calls 3

getPopularPagesFunction · 0.85
domwaiterFunction · 0.85

Tested by

no test coverage detected