From af27835be74279fe894318fe65d097ddff7384b0 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Sun, 21 Sep 2014 16:04:20 +0300 Subject: textanalysis: multiple changes to autocomplete 1. move the sugg variable to textanalysis.js instead of the ui part 2. use a callback for the autocomplete widget (it supports three options: array, string as url for a json returning service, or callback) 3. use a dictionary instead of an array to keep the list of suggestions. We iterate on the dictionary instead of using a Trie or some other datastructure in the callback. But the dictionary avoids iteration when adding a word. Overall a loss in performance, but not noticeable. Googling / memory suggests a Trie is what we want here, but I'm postponing that for later. See: http://ejohn.org/blog/javascript-trie-performance-analysis --- scripts/textanalysis-ui.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'scripts/textanalysis-ui.js') diff --git a/scripts/textanalysis-ui.js b/scripts/textanalysis-ui.js index b9e69ca7..6d6e2f5a 100644 --- a/scripts/textanalysis-ui.js +++ b/scripts/textanalysis-ui.js @@ -1,19 +1,15 @@ var text = ""; // Last text of sentence -var sugg = []; // suggestions for autocompletion of node names $('#textanalyser').autocompleteTrigger({ triggerStart: '#', triggerEnd: '', - source: sugg + source: autocompleteCallback }); // TODO - hide this in a scope function analyzeSentence(sentence, finalize) { var ret = TextAnalyser2(sentence, finalize); - for (var k in ret.sugg) { - sugg.push(ret.sugg[k]); - } switch (ret.state) { case ANALYSIS_NODE_START: $('.typeselection').css({top:window.innerHeight/2-115,left:window.innerWidth/2-325}); -- cgit v1.3.1