web/src/utils/do-searchy-searchy.ts
58 lines · 1708 bytes
1import type { Category } from '../types/Service';
2
3export const prepareSearchItems = (categories: Category[]) => {
4 const items: any = [];
5 // Add each category
6 categories.forEach(category => {
7 items.push({
8 type: 'Category',
9 category: category.name,
10 itemCount: (category.sections || []).reduce((acc, section) => {
11 return acc + (section.services || []).length;
12 }, 0),
13 });
14
15 // Add section with category context
16 category.sections.forEach(section => {
17 items.push({
18 type: 'Section',
19 sectionName: section.name,
20 description: section.intro || '',
21 category: category.name,
22 itemCount: (section.services || []).length,
23 });
24
25 // Add service with section and category context
26 (section.services || []).forEach(service => {
27 items.push({
28 type: 'Service',
29 name: service.name,
30 description: service.description,
31 url: service.url,
32 github: service.github || '',
33 category: category.name,
34 sectionName: section.name,
35 logo: service.icon || '',
36 });
37 });
38 });
39 });
40 return items;
41};
42
43export const searchOptions = {
44 includeScore: true,
45 keys: [
46 { name: 'name', weight: 0.9 },
47 { name: 'sectionName', weight: 0.8 },
48 { name: 'category', weight: 0.7 },
49 { name: 'notableMentions', weight: 0.5 },
50 { name: 'alternativeTo', weight: 0.5 },
51 { name: 'github', weight: 0.4 },
52 { name: 'url', weight: 0.2 },
53 { name: 'description', weight: 0.1 },
54 { name: 'intro', weight: 0.1 },
55 { name: 'furtherInfo', weight: 0.1 },
56 { name: 'wordOfWarning', weight: 0.1 },
57 ],
58};