-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
75 lines (54 loc) · 1.72 KB
/
search.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.4.4/fuse.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
<body>
<div id="papers">
<div>
<input id="searchbar" placeholder="Search the site...">
<button id="searchB">Search</button>
</div>
<ul class="list"></ul>
</div>
</body>
<script>
search = document.getElementById("searchbar");
searchB = document.getElementById("searchB");
var searchOptions = {
shouldSort: true,
threshold: 0.1,
tokenize: true,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
"Title",
"AuthorNames-Deduped",
"Abstract",
"AuthorKeywords"
]
};
var listOptions = {
valueNames: ['Title', 'AuthorNames-Deduped'],
// Since there are no elements in the list, this will be used as template.
item: '<li><h3 class="Title"></h3><p class="AuthorNames-Deduped"></p></li>'
};
d3.json('data/paperData.json', function(data) {
console.log(data);
var fuse = new Fuse(data, searchOptions);
var paperList = new List('papers', listOptions, []);
search.onkeyup = function() {
console.log('hi')
paperList.clear();
var result = fuse.search(search.value);
//var res = [];
//for (i=0; i < result.length; i++){
// res.push(result[i].item);
//}
paperList.add(result);
}
});
</script>