()
| 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 = () => |
no test coverage detected
searching dependent graphs…