fuzzy search

This commit is contained in:
azivner 2017-09-10 11:50:17 -04:00
parent 1f19c9cd0d
commit 19561191f6
3 changed files with 31 additions and 2 deletions

View file

@ -93,7 +93,7 @@
</form> </form>
</div> </div>
<div id="jumpToNoteDialog" title="Jumpt to note" style="display: none;"> <div id="jumpToNoteDialog" title="Jump to note" style="display: none;">
<form id="jumpToNoteForm"> <form id="jumpToNoteForm">
<div class="form-group"> <div class="form-group">
<label for="jumpToNoteAutocomplete">Jump to note</label> <label for="jumpToNoteAutocomplete">Jump to note</label>
@ -139,6 +139,8 @@
<script src="stat/lib/jquery.ui-contextmenu.min.js"></script> <script src="stat/lib/jquery.ui-contextmenu.min.js"></script>
<script src="stat/lib/fuse.min.js"></script>
<!-- https://github.com/ricmoo/aes-js --> <!-- https://github.com/ricmoo/aes-js -->
<script src="stat/lib/aes.js"></script> <script src="stat/lib/aes.js"></script>
<!-- https://github.com/emn178/js-sha256 --> <!-- https://github.com/emn178/js-sha256 -->

View file

@ -47,4 +47,22 @@ $(window).on('beforeunload', function(){
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved // this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
// this sends the request asynchronously and doesn't wait for result // this sends the request asynchronously and doesn't wait for result
saveNoteIfChanged(); saveNoteIfChanged();
}); });
// Overrides the default autocomplete filter function to search for matched on atleast 1 word in each of the input term's words
$.ui.autocomplete.filter = function (array, terms) {
const options = {
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
"value"
]
};
const fuse = new Fuse(array, options); // "list" is the item array
return fuse.search(terms);
};

9
static/lib/fuse.min.js vendored Normal file

File diff suppressed because one or more lines are too long