MCPcopy Index your code
hub / github.com/tinyplex/tinybase / searchLoad

Function searchLoad

site/js/common/search.ts:40–196  ·  view source on GitHub ↗
(isHome = false)

Source from the content-addressed store, hash-verified

38];
39
40export const searchLoad = (isHome = false) => {
41 addEventListener('load', () => {
42 const nav: HTMLElement = query('body > header > nav');
43 if (nav == null) {
44 return;
45 }
46
47 // Create UI
48 const search = createElement('div', null, {id: 'search'});
49 const input = createElement('input', search, {
50 type: 'text',
51 placeholder:
52 (navigator.platform.startsWith('Mac') ? '⌘' : 'cmd-') + 'K Search',
53 }) as HTMLInputElement;
54 const results = createElement('ol', search);
55 const noResults = createElement('li', results, {}, 'No results found');
56
57 // Create search store
58 const store = createStore();
59
60 // Define search index
61 const indexes = createIndexes(store);
62 indexes.setIndexDefinition(
63 'p',
64 'p',
65 // Put in slices based on prefixes of tokens
66 (getCell) => {
67 const slices: string[] = [];
68 (getCell('t') as string).split(' ').forEach((word) => {
69 for (let i = 0; i < word.length; i++) {
70 slices.push(word.slice(0, i + 1));
71 }
72 });
73 return slices;
74 },
75 't',
76 undefined,
77 // Rank by the density of early location of the slice in the text
78 (tokens1, tokens2, sliceId) =>
79 getWeighting(tokens2 as string, sliceId) -
80 getWeighting(tokens1 as string, sliceId),
81 );
82
83 // Load search store, hydrate 't' tokens cell, and enable input
84 fetch('/pages.json')
85 .then((response) => response.json())
86 .then((json) => {
87 store.transaction(() => {
88 store.setContent(json);
89 store.forEachRow('p', (path) => {
90 const {n, s} = store.getRow('p', path) as {n: string; s: string};
91 const tokens = new Set<string>();
92 tokenize(path, tokens, true);
93 tokenize(n, tokens);
94 tokenize(s, tokens);
95 store.setCell(
96 'p',
97 path,

Callers 2

home.tsFile · 0.90
app.tsFile · 0.90

Calls 14

queryFunction · 0.90
createElementFunction · 0.90
createStoreFunction · 0.90
getWeightingFunction · 0.85
tokenizeFunction · 0.85
bindUIFunction · 0.85
setIndexDefinitionMethod · 0.65
transactionMethod · 0.65
setContentMethod · 0.65
forEachRowMethod · 0.65
getRowMethod · 0.65
setCellMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…