From 572c19e6980568a6d3d9740f2ef1f2aabffe317e Mon Sep 17 00:00:00 2001 From: 3eef8a28f26fb2bcc514e6f1938929a1f931762 <116031952+3eef8a28f26fb2bcc514e6f1938929a1f931762@users.noreply.github.com> Date: Sat, 11 Feb 2023 18:10:30 -0500 Subject: [PATCH] Typo, also forgot to push a file --- js/search.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ search.html | 39 +++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 js/search.js create mode 100644 search.html diff --git a/js/search.js b/js/search.js new file mode 100644 index 000000000..3ba369dac --- /dev/null +++ b/js/search.js @@ -0,0 +1,65 @@ +// parses URL params +const params = window + .location + .search + .slice(1) + .split("&") + .map(p => p.split("=")) + .reduce((obj,[key,value]) => + ({ ...obj, [key]: decodeURIComponent(value) }), + {} + ); + +const search_term = params["search"]; + +const getSVG = function(name) { + return ''; +} + +const fuzzy_search_config = { + limit: 25, + includeScore: true, + ignoreLocation: true, + useExtendedSearch: true, + threshold: 0.01, + keys: [ + { + name: 'code', + weight: 0.1 + }, + { + name: 'description', + weight: 0.1 + }, + { + name: 'name', + weight: 0.8 + } + ] +} + +const display_search_results = function(searchable_catalog) { + const fuse = new Fuse(searchable_catalog,fuzzy_search_config); + console.log("Searching for " + search_term + "..."); + const results = fuse.search(search_term,{limit:fuzzy_search_config.limit}); + const table = document.getElementById("searchResultsContainer"); + results.forEach(function(search_entry) { + const entry = search_entry.item; + const tr = table.insertRow(-1); + tr.innerHTML += '' + + '

' + + entry.name + + '' + + entry.code + "

" + + "

" + entry.description + "

" + '\n'; + }); +} + +window.onload = function() { + // smart quotes + document.getElementById("searchTerm").innerHTML = "“" + search_term + "”"; + fetch("searchable_catalog.json") + .then(r => r.json()) + .then(display_search_results); +} diff --git a/search.html b/search.html new file mode 100644 index 000000000..bf27d0ab0 --- /dev/null +++ b/search.html @@ -0,0 +1,39 @@ + + + Quatalog Search + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+

+ Search results for +

+ +
+