Skip to content

Commit 5a340bf

Browse files
committed
docs: add algolia crawler config (closes #2592)
1 parent ad7ab9c commit 5a340bf

File tree

1 file changed

+114
-2
lines changed

1 file changed

+114
-2
lines changed

docs/reference/default-theme-search.md

+114-2
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ export default defineConfig({
7878
/**
7979
* @type {Pick<import('minisearch').Options, 'extractField' | 'tokenize' | 'processTerm'>}
8080
*/
81-
options: { /* ... */ },
81+
options: {
82+
/* ... */
83+
},
8284
/**
8385
* @type {import('minisearch').SearchOptions}
8486
* @default
8587
* { fuzzy: 0.2, prefix: true, boost: { title: 4, text: 2, titles: 1 } }
8688
*/
87-
searchOptions: { /* ... */ }
89+
searchOptions: {
90+
/* ... */
91+
}
8892
}
8993
}
9094
}
@@ -181,6 +185,114 @@ export default defineConfig({
181185

182186
[These options](https://github.com/vuejs/vitepress/blob/main/types/docsearch.d.ts) can be overridden. Refer official Algolia docs to learn more about them.
183187

188+
### Crawler Config
189+
190+
Here is an example config based on what this site uses:
191+
192+
```ts
193+
new Crawler({
194+
appId: '...',
195+
apiKey: '...',
196+
rateLimit: 8,
197+
startUrls: ['https://vitepress.dev/'],
198+
renderJavaScript: false,
199+
sitemaps: [],
200+
exclusionPatterns: [],
201+
ignoreCanonicalTo: false,
202+
discoveryPatterns: ['https://vitepress.dev/**'],
203+
schedule: 'at 05:10 on Saturday',
204+
actions: [
205+
{
206+
indexName: 'vitepress',
207+
pathsToMatch: ['https://vitepress.dev/**'],
208+
recordExtractor: ({ $, helpers }) => {
209+
return helpers.docsearch({
210+
recordProps: {
211+
lvl1: '.content h1',
212+
content: '.content p, .content li',
213+
lvl0: {
214+
selectors: '',
215+
defaultValue: 'Documentation'
216+
},
217+
lvl2: '.content h2',
218+
lvl3: '.content h3',
219+
lvl4: '.content h4',
220+
lvl5: '.content h5'
221+
},
222+
indexHeadings: true
223+
})
224+
}
225+
}
226+
],
227+
initialIndexSettings: {
228+
vitepress: {
229+
attributesForFaceting: ['type', 'lang'],
230+
attributesToRetrieve: ['hierarchy', 'content', 'anchor', 'url'],
231+
attributesToHighlight: ['hierarchy', 'hierarchy_camel', 'content'],
232+
attributesToSnippet: ['content:10'],
233+
camelCaseAttributes: ['hierarchy', 'hierarchy_radio', 'content'],
234+
searchableAttributes: [
235+
'unordered(hierarchy_radio_camel.lvl0)',
236+
'unordered(hierarchy_radio.lvl0)',
237+
'unordered(hierarchy_radio_camel.lvl1)',
238+
'unordered(hierarchy_radio.lvl1)',
239+
'unordered(hierarchy_radio_camel.lvl2)',
240+
'unordered(hierarchy_radio.lvl2)',
241+
'unordered(hierarchy_radio_camel.lvl3)',
242+
'unordered(hierarchy_radio.lvl3)',
243+
'unordered(hierarchy_radio_camel.lvl4)',
244+
'unordered(hierarchy_radio.lvl4)',
245+
'unordered(hierarchy_radio_camel.lvl5)',
246+
'unordered(hierarchy_radio.lvl5)',
247+
'unordered(hierarchy_radio_camel.lvl6)',
248+
'unordered(hierarchy_radio.lvl6)',
249+
'unordered(hierarchy_camel.lvl0)',
250+
'unordered(hierarchy.lvl0)',
251+
'unordered(hierarchy_camel.lvl1)',
252+
'unordered(hierarchy.lvl1)',
253+
'unordered(hierarchy_camel.lvl2)',
254+
'unordered(hierarchy.lvl2)',
255+
'unordered(hierarchy_camel.lvl3)',
256+
'unordered(hierarchy.lvl3)',
257+
'unordered(hierarchy_camel.lvl4)',
258+
'unordered(hierarchy.lvl4)',
259+
'unordered(hierarchy_camel.lvl5)',
260+
'unordered(hierarchy.lvl5)',
261+
'unordered(hierarchy_camel.lvl6)',
262+
'unordered(hierarchy.lvl6)',
263+
'content'
264+
],
265+
distinct: true,
266+
attributeForDistinct: 'url',
267+
customRanking: [
268+
'desc(weight.pageRank)',
269+
'desc(weight.level)',
270+
'asc(weight.position)'
271+
],
272+
ranking: [
273+
'words',
274+
'filters',
275+
'typo',
276+
'attribute',
277+
'proximity',
278+
'exact',
279+
'custom'
280+
],
281+
highlightPreTag: '<span class="algolia-docsearch-suggestion--highlight">',
282+
highlightPostTag: '</span>',
283+
minWordSizefor1Typo: 3,
284+
minWordSizefor2Typos: 7,
285+
allowTyposOnNumericTokens: false,
286+
minProximity: 1,
287+
ignorePlurals: true,
288+
advancedSyntax: true,
289+
attributeCriteriaComputedByMinProximity: true,
290+
removeWordsIfNoResults: 'allOptional'
291+
}
292+
}
293+
})
294+
```
295+
184296
<style>
185297
img[src="/search.png"] {
186298
width: 100%;

0 commit comments

Comments
 (0)