1 2let results; 3 4var index = elasticlunr(function () { 5 this.addField('full_text'); 6 this.setRef('id_str'); 7}); 8 9const searchInput = document.getElementById('search-input'); 10 11function processData(data) { 12 document.getElementById('loading').hidden = true; 13 document.getElementById('search').hidden = false; 14 for (doc of data) { 15 index.addDoc(doc); 16 } 17} 18 19processData(searchDocuments); 20 21function sortResults(criterion) { 22 if (criterion === 'newest-first') { 23 results = results.sort(function(a,b){ 24 return new Date(b.doc.created_at) - new Date(a.doc.created_at); 25 }); 26 renderResults(); 27 } 28 if (criterion === 'oldest-first') { 29 results = results.sort(function(a,b){ 30 return new Date(a.doc.created_at) - new Date(b.doc.created_at); 31 }); 32 renderResults(); 33 } 34 if (criterion === 'most-relevant') { 35 results = results.sort(function(a,b){ 36 return b.score - a.score; 37 }); 38 renderResults(); 39 } 40 if (criterion === 'most-popular') { 41 results = results.sort(function(a,b){ 42 return (+b.doc.favorite_count + +b.doc.retweet_count) - (+a.doc.favorite_count + +a.doc.retweet_count); 43 }); 44 renderResults(); 45 } 46} 47 48function renderResults() { 49 const output = results.map(item => `<div class="search_item"><div class="search_text">${item.doc.full_text}</div><div class="search_time">${new Date(item.doc.created_at).toLocaleString()}</div><div class="search_link"><a href="noah_st_amand/status/${item.doc.id_str}">link</a></div><hr class="search_divider" /></div>`.replace(/\.\.\/\.\.\/tweets_media\//g,'noah_st_amand/tweets_media/')); 50 document.getElementById('output').innerHTML = output.join(''); 51} 52 53function onSearchChange(e) { 54 results = index.search(e.target.value); 55 renderResults(); 56} 57searchInput.addEventListener('input', onSearchChange);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.