fuse_init.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Init search engine and index.
  3. */
  4. async function get_json(url) {
  5. try {
  6. const response = await fetch(url);
  7. if (!response.ok) {
  8. throw new Error(`Response status: ${response.status}`);
  9. }
  10. const json = await response.json();
  11. console.log(json);
  12. return json;
  13. } catch (error) {
  14. console.error(error.message);
  15. }
  16. }
  17. async function fuse_init() {
  18. let [idx_json, keys_json] = await Promise.all([
  19. get_json('/js/fuse_index.json'),
  20. get_json('/js/fuse_keys.json')
  21. ]);
  22. const fuseOptions = {
  23. // isCaseSensitive: false,
  24. // includeScore: false,
  25. // ignoreDiacritics: false,
  26. // shouldSort: true,
  27. // includeMatches: false,
  28. // findAllMatches: false,
  29. // minMatchCharLength: 1,
  30. // location: 0,
  31. // threshold: 0.6,
  32. // distance: 100,
  33. // useExtendedSearch: false,
  34. // ignoreLocation: false,
  35. // ignoreFieldNorm: false,
  36. // fieldNormWeight: 1,
  37. keys: keys_json,
  38. };
  39. return new Fuse(idx_json, fuseOptions);
  40. }