Vitepress
Tìm kiếm
Thêm tính năng tìm kiếm
- Cần thiết khi nhiều tài liệu
- Hỗ trợ tra cứu nhanh
Thêm tính năng search
Mở trang config.mts
Đưa đoạn code này vào trong themeConfig
themeConfig: {
search: {
provider: 'local',
options: {
miniSearch: {
/**
* @type {Pick<import('minisearch').Options, 'extractField' | 'tokenize' | 'processTerm'>}
*/
options: {
extractField: (document, fieldName) => {
return document[fieldName];
},
tokenize: (text: string) => {
return text.split(/[\s\-_,.]+/); // Tách từ bằng các ký tự phân cách cơ bản
}
},
/**
* @type {import('minisearch').SearchOptions}
* @default
* { fuzzy: 0.2, prefix: true, boost: { title: 4, text: 2, titles: 1 } }
*/
searchOptions: {
/* ... */
fuzzy: 0.2,
prefix: true,
boost: {
title: 4,
text: 2,
titles: 1
}
}
}
},
},Lưu ý các dấu đóng mở ngoặc cho phù hợp.
Thay option
Nếu không muốn dùng miniSearch Có thể thay bằng Algolia