MCPcopy
hub / github.com/tinyplex/tinybase / populateResults

Function populateResults

site/js/common/search.ts:121–165  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

119
120 // Populate results
121 const populateResults = () => {
122 const queryWords = input.value.toLowerCase().split(/[^a-z0-9]+/);
123 const pathWeights: Map<string, number> = new Map();
124 queryWords.forEach((queryWord) =>
125 indexes
126 .getSliceRowIds('p', queryWord)
127 .slice(0, 50)
128 .forEach((path) =>
129 pathWeights.set(
130 path,
131 (pathWeights.get(path) ?? 0) +
132 getWeighting(
133 store.getCell('p', path, 't') as string,
134 queryWord,
135 ),
136 ),
137 ),
138 );
139
140 const paths = Array.from(pathWeights.keys())
141 .sort(
142 (path1, path2) => pathWeights.get(path2)! - pathWeights.get(path1)!,
143 )
144 .slice(0, 10);
145
146 const newResults =
147 paths.length == 0
148 ? [noResults]
149 : paths.map((path, i) => {
150 const result = createElement('li');
151 const {n, s} = store.getRow('p', path) as {n: string; s: string};
152 highlighted(createElement('b', result), n, queryWords[0]);
153 highlighted(createElement('span', result), s, queryWords[0]);
154 result.title = s; // Show full summary on hover
155 result.addEventListener('mousedown', () =>
156 isHome ? (location.href = path) : go(path),
157 );
158 if (i == 0) {
159 addClass(result, 'hover');
160 }
161 return result;
162 });
163
164 results.replaceChildren(...newResults);
165 };
166
167 // Keyboard navigation
168 const bindKeyboard = () =>

Callers 1

bindUIFunction · 0.85

Calls 10

createElementFunction · 0.90
goFunction · 0.90
addClassFunction · 0.90
getWeightingFunction · 0.85
highlightedFunction · 0.85
getMethod · 0.80
addEventListenerMethod · 0.80
getSliceRowIdsMethod · 0.65
getCellMethod · 0.65
getRowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…