Cleaner proto
This commit is contained in:
parent
acc396cdfe
commit
afaa2e3d42
5
css/bootstrap.min.css
vendored
Normal file
5
css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
data/filters
BIN
data/filters
Binary file not shown.
@ -1 +1 @@
|
||||
{"index": ["../samples/cryptdevice_multi.html", "../samples/highmon_weechat.html"]}
|
||||
{"index": [{"title": "Decrypt multiple LUKS containers at boot on Arch", "url": "samples/cryptdevice_multi.html"}, {"title": "Hilight window in weechat", "url": "samples/highmon_weechat.html"}]}
|
32
index.html
32
index.html
@ -2,21 +2,35 @@
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>BloomJS demo</title>
|
||||
<title>BloomySearch</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<style type="text/css">
|
||||
#error {
|
||||
font-weight: bold;
|
||||
color: red;
|
||||
body {
|
||||
background-image: url('bg.png');
|
||||
}
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
.container {
|
||||
background-color: white;
|
||||
min-height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Bloom.JS demo</h1>
|
||||
<p id="error"></p>
|
||||
<div id="main">
|
||||
<p>Loading…</p>
|
||||
<div class="container">
|
||||
<h1 class="text-right">BloomySearch</h1>
|
||||
<hr/>
|
||||
<p id="error"></p>
|
||||
<div id="main">
|
||||
<p class="alert alert-info">Loading…</p>
|
||||
</div>
|
||||
<div id="results"></div>
|
||||
|
||||
<h2 class="text-right" style="margin-top: 3em;">More about BloomySearch</h2>
|
||||
<hr/>
|
||||
</div>
|
||||
<div id="results"></div>
|
||||
<script type="text/javascript" src="js/bloom.js"></script>
|
||||
<script type="text/javascript" src="js/stemmer.js"></script>
|
||||
<script type="text/javascript" src="js/app.js"></script>
|
||||
|
@ -123,11 +123,10 @@ class BloomFilter():
|
||||
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||
"""
|
||||
v -= ctypes.c_int(ctypes.c_int(v >> 1).value & ctypes.c_int(0x55555555).value).value
|
||||
v = ctypes.c_int(v & 0x33333333).value + c_types.c_int(ctypes.c_int(v >> 2).value & 0x33333333).value
|
||||
v = ctypes.c_int(v & 0x33333333).value + ctypes.c_int(ctypes.c_int(v >> 2).value & 0x33333333).value
|
||||
return ctypes.c_int((ctypes.c_int((v + ctypes.c_int(v >> 4).value) & 0xF0F0F0F).value * 0x1010101) >> 24).value
|
||||
|
||||
|
||||
def rshift(self,val, n):
|
||||
def rshift(self, val, n):
|
||||
"""
|
||||
Implements the >>> JS operator.
|
||||
|
||||
|
@ -36,7 +36,10 @@ def remove_common_words(words):
|
||||
|
||||
if __name__ == "__main__":
|
||||
error_rate = 0.1
|
||||
|
||||
os.chdir(os.path.dirname(sys.argv[0]))
|
||||
samples = list_directory("../samples/")
|
||||
pages = []
|
||||
filters = []
|
||||
p = stemmer.PorterStemmer()
|
||||
|
||||
@ -58,12 +61,14 @@ if __name__ == "__main__":
|
||||
|
||||
tmp_filter = bloom.BloomFilter(capacity=len(words),
|
||||
error_rate=error_rate)
|
||||
words = json.loads('["solut", "devic", "cryptkey2", "contain", "chang", "thi", "conf", "ckeyfiin", "support", "load", "here", "laptop", "file", "exampl", "paramet", "cryptsetup", "when", "proce", "line", "cryptkei", "wiki", "edit", "present", "describ", "ckei", "grub", "first", "warn", "mkinitcpio", "with", "updat", "mount", "manual", "ckeybyif", "least", "need", "multipl", "also", "found", "arch", "then", "us", "encrypt", "packag", "that", "over", "someth", "hook", "doesn", "avail", "avoid", "work", "which", "provid", "order", "initcpio", "anoth", "setup", "mean", "necessari", "default", "disk", "best", "linemkdir", "luk", "system", "unlock", "occurr", "requir", "command", "abl", "cryptdevice2", "encrypt2", "instal", "multi", "last", "extend", "obsolet", "boot", "your", "achiev", "second", "mkdir", "stuff", "final", "displai", "concern", "ad", "cryptdevic", "more", "copi"]')
|
||||
for word in words:
|
||||
tmp_filter.add(word)
|
||||
|
||||
filters.append(tmp_filter.buckets)
|
||||
|
||||
pages.append({"title": re.search(r"@title=(.*)\n", content).group(1),
|
||||
"url": sample[3:]})
|
||||
|
||||
# First Int32 is length
|
||||
filters_to_write = struct.pack("<i", len(filters))
|
||||
# Then comes the length of each filter
|
||||
@ -78,4 +83,4 @@ if __name__ == "__main__":
|
||||
index_fh.write(filters_to_write)
|
||||
|
||||
with open("../data/pages.json", "w") as pages_fh:
|
||||
pages_fh.write(json.dumps({"index": samples}))
|
||||
pages_fh.write(json.dumps({"index": pages}))
|
||||
|
23
js/app.js
23
js/app.js
@ -15,7 +15,7 @@ function callback() {
|
||||
|
||||
// Sets up the page, that is now ready
|
||||
ready = true;
|
||||
document.getElementById('main').innerHTML = '<form id="search_form"><p><input type="text" id="search" name="search" placeholder="Search for articles..."/></p></form>';
|
||||
document.getElementById('main').innerHTML = '<form role="form" id="search_form"><p class="form-group"><label for="search">What are you thinking about?</label><input class="form-control" type="text" id="search" name="search" placeholder="Type something to search for…"/></p></form>';
|
||||
|
||||
// Handle onchange actions
|
||||
document.getElementById('search').oninput = function (e) {
|
||||
@ -23,7 +23,12 @@ function callback() {
|
||||
return;
|
||||
}
|
||||
|
||||
filter_results(e.target.value);
|
||||
if (e.target.value !== "") {
|
||||
filter_results(e.target.value);
|
||||
}
|
||||
else {
|
||||
document.getElementById("results").innerHTML = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,14 +58,14 @@ function filter_results(query) {
|
||||
}
|
||||
|
||||
if (results.length > 0) {
|
||||
results_html = '<ul>';
|
||||
results_html = '<h4>' + results.length + ' results found:</h4><div>';
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
results_html += '<li>' + results[i] + '</li>';
|
||||
results_html += '<a href="' + results[i]["url"] + '" class="list-group-item">' + results[i]["title"] + '</a>';
|
||||
}
|
||||
results_html += '</ul>'
|
||||
results_html += '</div>'
|
||||
}
|
||||
else {
|
||||
results_html = '<p>Aucun résultat.</p>';
|
||||
results_html = '<p class="alert alert-danger">No results found =(</p>';
|
||||
}
|
||||
document.getElementById('results').innerHTML = results_html;
|
||||
}
|
||||
@ -90,14 +95,14 @@ oReq.onload = function (oEvent) {
|
||||
tmp_array = byte_array.subarray(1 + nb_bloom_filters + l, 1 + nb_bloom_filters + l + lengths[i]);
|
||||
var l = lengths[i];
|
||||
bloom.push(new BloomFilter(tmp_array, error_rate));
|
||||
console.log(tmp_array);
|
||||
console.log(bloom[0].test("concern"));
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
else {
|
||||
document.getElementById('error').innerHTML = 'Unable to load the bloom filters.';
|
||||
var error = document.getElementById('error');
|
||||
error.innerHTML = 'Unable to load the bloom filters.';
|
||||
error.className = "alert alert-danger";
|
||||
}
|
||||
};
|
||||
oReq.send(null);
|
||||
|
Loading…
Reference in New Issue
Block a user