From b267420d3bb731dc072033d8415f1e47d714ce96 Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Fri, 19 Apr 2013 10:21:39 -0400 Subject: [PATCH 1/3] Increase the boost for prefix matches. This is a fix for #3411 and is going to be useful for code hinting --- src/utils/StringMatch.js | 6 ++++++ test/spec/StringMatch-test.js | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/utils/StringMatch.js b/src/utils/StringMatch.js index 26c6827306c..2bba7bc77c9 100644 --- a/src/utils/StringMatch.js +++ b/src/utils/StringMatch.js @@ -562,6 +562,12 @@ define(function (require, exports, module) { // handles the initial value of lastMatchIndex which is used for // constructing ranges but we don't yet have a true match. if (score > 0 && lastMatchIndex + 1 === c) { + // Continue boosting for each additional match at the beginning + // of the name + if (c - numConsecutive === lastSegmentStart) { + newPoints += BEGINNING_OF_NAME_POINTS; + } + // Consecutive matches that started on a special are a // good indicator of intent, so we award an added bonus there. if (currentRangeStartedOnSpecial) { diff --git a/test/spec/StringMatch-test.js b/test/spec/StringMatch-test.js index ff640be1653..8606ab7bcc6 100644 --- a/test/spec/StringMatch-test.js +++ b/test/spec/StringMatch-test.js @@ -545,8 +545,25 @@ define(function (require, exports, module) { it("should find the right jsu", function () { expect(goodRelativeOrdering("jsu", [ - "src/language/JSLintUtils.js", - "src/language/JSUtil.js" + "src/language/JSUtil.js", + "src/language/JSLintUtils.js" + ])).toBe(true); + }); + + it("should prefer prefix matches", function () { + expect(goodRelativeOrdering("asc", [ + "ASC.js", + "ActionScriptCompiler.js" + ])).toBe(true); + expect(goodRelativeOrdering("st", [ + "str", + "String", + "stringMatch", + "StringMatcher", + "screenTop", + "scrollTo", + "setTimeout", + "switch" ])).toBe(true); }); }); From c667fcb77054f4f7b6ba3d5df7ecd98a00310579 Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Tue, 23 Apr 2013 10:30:28 -0400 Subject: [PATCH 2/3] Make numConsecutive actually mean what it says. In the process, I tweaked the bonuses to keep things ordered well. --- src/utils/StringMatch.js | 16 ++++++++++++---- test/spec/StringMatch-test.js | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/utils/StringMatch.js b/src/utils/StringMatch.js index 2bba7bc77c9..539fc6dd157 100644 --- a/src/utils/StringMatch.js +++ b/src/utils/StringMatch.js @@ -119,9 +119,9 @@ define(function (require, exports, module) { var SPECIAL_POINTS = 35; var MATCH_POINTS = 10; var LAST_SEGMENT_BOOST = 1; - var BEGINNING_OF_NAME_POINTS = 25; + var BEGINNING_OF_NAME_POINTS = 10; var DEDUCTION_FOR_LENGTH = 0.2; - var CONSECUTIVE_MATCHES_POINTS = 10; + var CONSECUTIVE_MATCHES_POINTS = 7; var NOT_STARTING_ON_SPECIAL_PENALTY = 25; // Used in match lists to designate matches of "special" characters (see @@ -565,13 +565,21 @@ define(function (require, exports, module) { // Continue boosting for each additional match at the beginning // of the name if (c - numConsecutive === lastSegmentStart) { + if (DEBUG_SCORES) { + scoreDebug.beginning += BEGINNING_OF_NAME_POINTS; + } newPoints += BEGINNING_OF_NAME_POINTS; } - + + numConsecutive++; + // Consecutive matches that started on a special are a // good indicator of intent, so we award an added bonus there. if (currentRangeStartedOnSpecial) { - numConsecutive++; + newPoints += CONSECUTIVE_MATCHES_POINTS * numConsecutive; + if (DEBUG_SCORES) { + scoreDebug.consecutive += CONSECUTIVE_MATCHES_POINTS * numConsecutive; + } } if (DEBUG_SCORES) { diff --git a/test/spec/StringMatch-test.js b/test/spec/StringMatch-test.js index 8606ab7bcc6..702e59f924a 100644 --- a/test/spec/StringMatch-test.js +++ b/test/spec/StringMatch-test.js @@ -550,6 +550,13 @@ define(function (require, exports, module) { ])).toBe(true); }); + it("should find the right trange", function () { + expect(goodRelativeOrdering("trange", [ + "src/document/TextRange.js", + "src/extensions/default/JavaScriptQuickEdit/unittest-files/jquery-ui/demos/slider/range.html" + ])).toBe(true); + }); + it("should prefer prefix matches", function () { expect(goodRelativeOrdering("asc", [ "ASC.js", From 15528902598f66534908930786291528ac9118b5 Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Tue, 23 Apr 2013 21:22:45 -0400 Subject: [PATCH 3/3] Extract consecutive boost value to variable. Per review feedback --- src/utils/StringMatch.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/utils/StringMatch.js b/src/utils/StringMatch.js index 539fc6dd157..89dab643b08 100644 --- a/src/utils/StringMatch.js +++ b/src/utils/StringMatch.js @@ -573,19 +573,18 @@ define(function (require, exports, module) { numConsecutive++; + var boost = CONSECUTIVE_MATCHES_POINTS * numConsecutive; + // Consecutive matches that started on a special are a // good indicator of intent, so we award an added bonus there. if (currentRangeStartedOnSpecial) { - newPoints += CONSECUTIVE_MATCHES_POINTS * numConsecutive; - if (DEBUG_SCORES) { - scoreDebug.consecutive += CONSECUTIVE_MATCHES_POINTS * numConsecutive; - } + boost = boost * 2; } if (DEBUG_SCORES) { - scoreDebug.consecutive += CONSECUTIVE_MATCHES_POINTS * numConsecutive; + scoreDebug.consecutive += boost; } - newPoints += CONSECUTIVE_MATCHES_POINTS * numConsecutive; + newPoints += boost; } else { numConsecutive = 1; }