From f28edd6bcb2a84e7c36700af102006c95468a265 Mon Sep 17 00:00:00 2001 From: Niklas Baumstark Date: Fri, 27 Jan 2012 21:45:01 +0100 Subject: small changes --- lib/completion.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/completion.js') diff --git a/lib/completion.js b/lib/completion.js index b3e70516..58f140f9 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -63,19 +63,18 @@ var completion = (function() { return null; } - /** Calculates a very simple similarity value between a :query and a :string. The current - * implementation simply returns the cumulated length of query parts that are also found - * in the string, raised to the power of 3. - */ + /** Calculates a very simple similarity value between a :query and a :string */ self.calculateRelevancy = function(query, str) { query = self.normalize(query); str = self.normalize(str); var sum = 0; + // only iterate over slices of the query starting at an offset up to 10 to save resources for (var start = 0; start < 20 && start < query.length; ++start) { for (var i = query.length; i >= start; --i) { if (str.indexOf(query.slice(start, i)) >= 0) { - sum += (i - start) * (i - start); + var length = i - start; + sum += length * length; break; } } @@ -173,7 +172,7 @@ var completion = (function() { var htmlRegex = /<[^>]*>|&[a-z]+;/gi; - /** Strips HTML tags and escape sequences using a naive regex replacement. Optionally, saves the stripped + /** Strips HTML tags and entities using a naive regex replacement. Optionally, saves the stripped * HTML tags in a dictionary indexed by the position where the tag should be reinserted. */ function stripHtmlTags(str, positions) { if (!positions) -- cgit v1.2.3