GitHub

@@ -17,17 +17,17 @@

1717

<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">

1818

</script>

1919

<script id="search_algo" type="module">

20-

import Fuse from "https://cdn.jsdelivr.net/npm/fuse.js@6.6.2/dist/fuse.esm.js";

20+

import FlexSearch from 'https://cdn.jsdelivr.net/npm/flexsearch@0.7.43/+esm'

212122-

const index = {{ index|tojson }};

23-24-

const options = {

25-

includeMatches: true,

26-

includeScore: true,

27-

keys: ["title", "contents"],

28-

useExtendedSearch: true,

29-

};

30-

const fuse = new Fuse(index, options);

22+

const index = new FlexSearch.Document({

23+

context: true,

24+

document: {

25+

index: ["title", "contents"],

26+

}

27+

});

28+

const documents = {{index | tojson }};

29+

Object.values(documents).forEach(doc => index.add(doc));

30+

window.windex = index;

31313232

function render(tag, attributes, ...children) {

3333

const elt = document.createElement(tag);

@@ -49,25 +49,24 @@

4949

return;

5050

}

515152-

const result = fuse.search(query);

52+

const result = index.search(query, {limit: 25}).map(x => x.result).flat();

53+

console.log(result);

535454-

for (let i = 0; i < Math.min(25, result.length); i++) {

55-

const { contents, link_path, title_path } = result[i].item;

56-

const indices = result[i].matches.filter((x) => x.key === "contents")[0]

57-

?.indices;

55+

for (let i of result.splice(0, 25)) {

56+

const {contents, link_path, title_path} = documents[i];

5857

resultsList.appendChild(

5958

render(

6059

"li",

61-

{ class: "result" },

60+

{class: "result"},

6261

render(

6362

"a",

64-

{ class: "title_path", href: `../${link_path}` },

63+

{class: "title_path", href: `../${link_path}`},

6564

title_path

6665

),

6766

render(

6867

"div",

69-

{ class: "contents" },

70-

contents.substring(indices ? indices[0][0] : 0, 255)

68+

{class: "contents"},

69+

contents.replace(/<[^>]+>/gi, "").substring(0, 255)

7170

)

7271

)

7372

);

@@ -90,29 +89,33 @@

9089

<!-- visitor counter that does not track personal info -->

9190

<script data-goatcounter="https://goatcounter.billmill.org/count" async

9291

src="//goatcounter.billmill.org/count.js"></script>

93-

<style>

94-

#searchContainer {

95-

width: 100%;

96-

display: flex;

97-

align-items: center;

98-

justify-content: center;

99-

}

100-

#search {

101-

width: 75%;

102-

font-size: 2rem;

103-

padding: 5px;

104-

}

105-

.title_path {

106-

font-size: 1.1em;

107-

padding-bottom: .25em;

108-

}

109-

ul {

110-

list-style-type: none;

111-

}

112-

li {

113-

padding-top: 1em;

114-

}

115-

</style>

92+

<style>

93+

#searchContainer {

94+

width: 100%;

95+

display: flex;

96+

align-items: center;

97+

justify-content: center;

98+

}

99+100+

#search {

101+

width: 75%;

102+

font-size: 2rem;

103+

padding: 5px;

104+

}

105+106+

.title_path {

107+

font-size: 1.1em;

108+

padding-bottom: .25em;

109+

}

110+111+

ul {

112+

list-style-type: none;

113+

}

114+115+

li {

116+

padding-top: 1em;

117+

}

118+

</style>

116119

<link rel="stylesheet" href="/style.css" type="text/css" />

117120

<link rel="stylesheet" href="/pygments.css" type="text/css" />

118121

<link rel="alternate" type="application/atom+xml" title="Atom" href="/atom.xml">

Read the original on github.com ↗