1 function el(element, config) {
2 const e = document.createElement(element);
6 for(const child of config.children.filter(a => a)) {
10 delete config.children;
13 for(const key in config) {
21 async function setup_lunr() {
22 const index_json = await (await fetch('/archives/lunr.json')).json();
23 const num_docs = index_json.length;
24 const search_index = elasticlunr(function() {
25 this.addField('title');
26 this.addField('author');
30 for(const doc of index_json) {
31 search_index.addDoc(doc);
34 return [search_index, num_docs];
37 setup_lunr().then(([index, num_docs]) => {
38 const params = new URLSearchParams(window.location.search);
39 const query = params.get('query');
40 const submissionList = document.getElementById('searchResults');
41 const results = index.search(query, {});
42 submissionList.innerHTML = '';
43 submissionList.className = 'submissionList';
44 submissionList.appendChild(el('div', {
45 className: 'submissionItem',
48 textContent: `${results.length} results for "${query}" (out of ${num_docs} archived posts)`
53 for(const r of results) {
54 submissionList.appendChild(el('div', {
55 className: 'submissionItem',
59 textContent: r.doc.score
62 className: 'submissionContent',
68 href: `/archives/thread/${r.doc.id}`,
70 r.doc.link_flair_text &&
73 textContent: `${r.doc.link_flair_text} `
76 textContent: r.doc.title
80 r.doc.url && el('span', {
85 innerHTML: ` <span class="truncate">${r.doc.url}</span>`
92 className: 'subtitle',
95 textContent: `posted at ${r.doc.created_date} by `
99 textContent: `u/${r.doc.author}`
104 className: 'subtitle',
107 href: `/archives/thread/${r.doc.id}`,
108 textContent: `${r.doc.num_comments} comments`