1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/* eslint-env browser */
async function initSearch() {
const {FlexSearch} = window;
// Copied directly from server search.js
window.indexes = {
albums: new FlexSearch.Document({
id: "reference",
index: ["name", "groups"],
}),
tracks: new FlexSearch.Document({
id: "reference",
index: ["track", "album", "artists", "directory", "additionalNames"],
}),
artists: new FlexSearch.Document({
id: "reference",
index: ["names"],
}),
};
const searchData =
await fetch('/search-data/index.json')
.then(resp => resp.json());
for (const [indexName, indexData] of Object.entries(searchData)) {
for (const [key, value] of Object.entries(indexData)) {
window.indexes[index_key].import(key, value);
}
}
}
function searchAll(query, options = {}) {
const results = {};
for (const [indexName, index] of Object.entries(window.indexes)) {
results[indexName] = index.search(query, options);
}
return results;
}
document.addEventListener('DOMContentLoaded', initSearch);
|