layout | title |
---|---|
page |
GTN Tutorial Search |
{% icon search %}
<script>
var resources = {% dump_search_view testing %};
function search(idx, q, includeFaqs, includeTutorials){
if(q.length > 2){
var results_partial = idx.search(`*${q}*`),
results_exact = idx.search(`${q}`),
results_fuzzy = idx.search(`${q}~3`);
// Include search term in page title
document.getElementsByTagName("title")[0].innerText = `${q} | GTN Tutorial Search`
thereMap = Object.assign({}, ...results_partial.map((x) => ({[x.ref]: x.score})));
results_exact.forEach(x => {
if(thereMap[x.ref] !== undefined){
if(thereMap[x.ref] < x.score + 4){
thereMap[x.ref] = x.score + 4
}
} else {
thereMap[x.ref] = x.score + 4
}
})
results_fuzzy.forEach(x => {
if(thereMap[x.ref] !== undefined){
if(thereMap[x.ref] < x.score - 2){
thereMap[x.ref] = x.score - 2
}
} else {
thereMap[x.ref] = x.score - 2
}
})
combined_results = Object.getOwnPropertyNames(thereMap);
combined_results.sort((a, b) => {
if (thereMap[a] > thereMap[b]) {
return -1;
}
if (thereMap[a] < thereMap[b]) {
return 1;
}
return 0;
});
var results_final = combined_results.map(x => {
return resources['/' + x.replaceAll(".md", ".html")];
}).filter(x => x !== undefined);
if(! includeFaqs) {
results_final = results_final.filter(x => x.type != 'FAQ')
}
if(! includeTutorials) {
results_final = results_final.filter(x => x.type != 'Tutorial')
}
$("#results-container").html(results_final.map(x => `
<input type="checkbox" id="search-faqs" name="search-faqs" checked>
<label for="search-faqs">Search FAQs</label>
<input type="checkbox" id="search-tutorials" name="search-tutorials" checked>
<label for="search-tutorials">Search Tutorials</label>
<div class="search-results row" id="results-container"></div>