@@ -36,8 +36,26 @@ module.exports.register = function () {
36
36
*/
37
37
function collectPages ( contentCatalog , siteUrl ) {
38
38
const all = [ ] ;
39
+
40
+ // Define which server-admin versions to exclude from indexing
41
+ const excludedServerAdminVersions = [
42
+ 'server-v4.1' ,
43
+ 'server-v4.2' ,
44
+ 'server-v4.3' ,
45
+ 'server-v4.4' ,
46
+ 'server-v4.5' ,
47
+ 'server-v4.6' ,
48
+ 'server-v4.7'
49
+ ] ;
50
+
39
51
contentCatalog . getComponents ( ) . forEach ( ( { name : comp , versions } ) => {
40
52
versions . forEach ( ( { version } ) => {
53
+ // Skip indexing for excluded server-admin versions
54
+ if ( comp === 'server-admin' && excludedServerAdminVersions . includes ( version ) ) {
55
+ console . log ( `Skipping Algolia indexing for server-admin version: ${ version } ` ) ;
56
+ return ; // Skip this entire component version
57
+ }
58
+
41
59
const compVer = contentCatalog . getComponentVersion ( comp , version ) ;
42
60
const navMap = getNavEntriesByUrl ( compVer . navigation ) ;
43
61
contentCatalog
@@ -107,25 +125,25 @@ function hasAlgoliaCredentials() {
107
125
function chunkText ( text , maxBytes = 8500 ) { // Reduced from 10000 to have margin for metadata
108
126
const chunks = [ ] ;
109
127
let current = '' ;
110
-
128
+
111
129
text . split ( / \n \n / ) . forEach ( paragraph => {
112
130
const para = paragraph + '\n\n' ;
113
131
const combined = current + para ;
114
132
const size = Buffer . byteLength ( combined , 'utf8' ) ;
115
-
133
+
116
134
if ( size > maxBytes ) {
117
135
if ( current ) chunks . push ( current . trim ( ) ) ;
118
-
136
+
119
137
if ( Buffer . byteLength ( para , 'utf8' ) > maxBytes ) {
120
138
// Paragraph too big: split by sentences
121
139
let sentenceBuf = '' ;
122
140
paragraph . split ( / (?< = \. ) \s / ) . forEach ( sentence => {
123
141
const combinedSentence = sentenceBuf + sentence + ' ' ;
124
142
const sentSize = Buffer . byteLength ( combinedSentence , 'utf8' ) ;
125
-
143
+
126
144
if ( sentSize > maxBytes ) {
127
145
if ( sentenceBuf ) chunks . push ( sentenceBuf . trim ( ) ) ;
128
-
146
+
129
147
if ( Buffer . byteLength ( sentence , 'utf8' ) > maxBytes ) {
130
148
// Sentence too big: split by characters
131
149
let charBuf = '' ;
@@ -144,7 +162,7 @@ function chunkText(text, maxBytes = 8500) { // Reduced from 10000 to have margi
144
162
sentenceBuf = combinedSentence ;
145
163
}
146
164
} ) ;
147
-
165
+
148
166
if ( sentenceBuf ) chunks . push ( sentenceBuf . trim ( ) ) ;
149
167
current = '' ;
150
168
} else {
@@ -154,7 +172,7 @@ function chunkText(text, maxBytes = 8500) { // Reduced from 10000 to have margi
154
172
current = combined ;
155
173
}
156
174
} ) ;
157
-
175
+
158
176
if ( current ) chunks . push ( current . trim ( ) ) ;
159
177
return chunks ;
160
178
}
@@ -170,12 +188,12 @@ async function indexToAlgolia(pages) {
170
188
171
189
const client = algoliasearch ( appId , apiKey ) ;
172
190
const records = [ ] ;
173
-
191
+
174
192
pages . forEach ( ( p ) => {
175
193
const pathId = p . relUrl . replace ( / ^ \/ + / , '' ) . replace ( / [ \/ ] / g, '_' ) ;
176
194
const baseId = `${ p . component } :${ p . version } :${ pathId } ` ;
177
195
const chunks = chunkText ( p . text ) ;
178
-
196
+
179
197
chunks . forEach ( ( chunk , i ) => {
180
198
// Create the record with all fields except content
181
199
const record = {
@@ -187,26 +205,26 @@ async function indexToAlgolia(pages) {
187
205
version : p . version ,
188
206
objectID : `${ baseId } :${ i } ` ,
189
207
} ;
190
-
208
+
191
209
// Calculate metadata size
192
210
const metadataSize = Buffer . byteLength ( JSON . stringify ( record ) , 'utf8' ) ;
193
211
// Maximum allowed content size
194
212
const maxContentSize = 9500 - metadataSize ;
195
-
213
+
196
214
// Trim content if necessary to ensure total record size is under limit
197
215
let content = chunk ;
198
216
if ( Buffer . byteLength ( content , 'utf8' ) > maxContentSize ) {
199
217
content = content . slice ( 0 , Math . floor ( maxContentSize * 0.9 ) ) ;
200
218
}
201
-
219
+
202
220
record . content = content ;
203
221
records . push ( record ) ;
204
222
} ) ;
205
223
} ) ;
206
-
224
+
207
225
console . log ( `Prepared ${ records . length } chunked records for indexing` ) ;
208
226
209
-
227
+
210
228
// Configure index settings with path faceting
211
229
try {
212
230
const settingsResponse = await client . setSettings ( {
@@ -220,9 +238,9 @@ async function indexToAlgolia(pages) {
220
238
paginationLimitedTo : 1000 ,
221
239
} ,
222
240
} ) ;
223
-
241
+
224
242
console . log ( `Applied index settings, task ID: ${ settingsResponse . taskID } ` ) ;
225
-
243
+
226
244
// Wait for task completion
227
245
await waitForTask ( client , indexName , settingsResponse . taskID ) ;
228
246
console . log ( 'Index settings update completed successfully' ) ;
@@ -233,7 +251,7 @@ async function indexToAlgolia(pages) {
233
251
234
252
const response = await client . saveObjects ( { indexName, objects : records } ) ;
235
253
console . log ( `Indexed ${ response [ 0 ] ?. objectIDs . length } records to ${ indexName } ` ) ;
236
-
254
+
237
255
return response ;
238
256
}
239
257
@@ -247,17 +265,17 @@ async function indexToAlgolia(pages) {
247
265
*/
248
266
async function waitForTask ( client , indexName , taskID , timeout = 60000 , pollInterval = 1000 ) {
249
267
const startTime = Date . now ( ) ;
250
-
268
+
251
269
while ( Date . now ( ) - startTime < timeout ) {
252
270
const taskResponse = await client . getTask ( { indexName, taskID } ) ;
253
-
271
+
254
272
if ( taskResponse . status === 'published' ) {
255
273
return taskResponse ;
256
274
}
257
-
275
+
258
276
// Wait before checking again
259
277
await new Promise ( resolve => setTimeout ( resolve , pollInterval ) ) ;
260
278
}
261
-
279
+
262
280
throw new Error ( `Task ${ taskID } timed out after ${ timeout } ms` ) ;
263
281
}
0 commit comments