PageSourceSearch

https://investigate.ai/js/lunrclient.js

js investigate.ai collected 2026-10-03 21:37:39 UTC 2,662 bytes, 96 lines download raw bytes

1"use strict";
2
3var LUNR_CONFIG = {
4    "resultsElementId": "searchResults",  // Element to contain results
5    "countElementId": "resultCount"  // Element showing number of results
6};
7
8
9// Get URL arguments
10function getParameterByName(name, url) {
11    if (!url) url = window.location.href;
12    name = name.replace(/[\[\]]/g, "\\$&");
13    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
14        results = regex.exec(url);
15    if (!results) return null;
16    if (!results[2]) return "";
17    return decodeURIComponent(results[2].replace(/\+/g, " "));
18}
19
20
21// Parse search results into HTML
22function parseLunrResults(results) {
23    var html = [];
24    for (var i = 0; i < results.length; i++) {
25        var id = results[i]["ref"];
26        var item = PREVIEW_LOOKUP[id]
27        var title = item["t"];
28        var preview = item["p"];
29        var link = item["l"];
30        var result = ('<p><span class="result-title"><a href="' + link + '">'
31                    + title + '</a></span><br><span class="result-preview">'
32                    + preview + '</span></p>');
33        html.push(result);
34    }
35    if (html.length) {
36        return html.join("");
37    }
38    else {
39        return "<p>Your search returned no results.</p>";
40    }
41}
42
43
44function escapeHtml(unsafe) {
45    return unsafe
46         .replace(/&/g, "&amp;")
47         .replace(/</g, "&lt;")
48         .replace(/>/g, "&gt;")
49         .replace(/"/g, "&quot;")
50         .replace(/'/g, "&#039;");
51}
52
53
54function showResultCount(query, total, domElementId) {
55    if (total == 0) {
56        return;
57    }
58
59    var s = "";
60    if (total > 1) {
61        s = "s";
62    }
63    var found = "<p>Found " + total + " result" + s;
64    if (query != "" && query != null) {
65        query = escapeHtml(query);
66        var forQuery = ' for <span class="result-query">' + query + '</span>';
67    }
68    else {
69        var forQuery = "";
70    }
71    var element = document.getElementById(domElementId);
72    element.innerHTML = found + forQuery + "</p>";
73}
74
75
76function searchLunr(query) {
77    var idx = lunr.Index.load(LUNR_DATA);
78    // Write results to page
79    var results = idx.search(query);
80    var resultHtml = parseLunrResults(results);
81    var elementId = LUNR_CONFIG["resultsElementId"];
82    document.getElementById(elementId).innerHTML = resultHtml;
83
84    var count = results.length;
85    showResultCount(query, count, LUNR_CONFIG["countElementId"]);
86}
87
88
89// When the window loads, read query parameters and perform search
90window.onload = function() {
91    var query = getParameterByName("q");
92    if (query != "" && query != null) {
93        document.forms.lunrSearchForm.q.value = query;
94        searchLunr(query);
95    }
96};

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.