Title: [207782] trunk
Revision
207782
Author
commit-qu...@webkit.org
Date
2016-10-24 14:48:13 -0700 (Mon, 24 Oct 2016)

Log Message

Web Inspector: Improve Quick Open sorting algorithm
https://bugs.webkit.org/show_bug.cgi?id=163705

Patch by Devin Rousso <dcrousso+web...@gmail.com> on 2016-10-24
Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

* UserInterface/Models/ResourceQueryResult.js:
(WebInspector.ResourceQueryResult.prototype._calculateRank.getMultiplier):
(WebInspector.ResourceQueryResult.prototype._calculateRank):
Added logic to multiply the ranking increment/decrement based on whether the current match
is part of a sequence, whether that sequence began with a special character, and the length
of the current sequence.

LayoutTests:

* inspector/unit-tests/resource-query-controller-expected.txt:
* inspector/unit-tests/resource-query-controller.html:
Changed the ExecuteQueryGeneralRankings and ExecuteQueryPositionRankings tests to reflect
the new ranking logic.  Added ExecuteQueryConsecutiveRankings to test more realistic
scenarios and ensure better ranking.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (207781 => 207782)


--- trunk/LayoutTests/ChangeLog	2016-10-24 21:44:34 UTC (rev 207781)
+++ trunk/LayoutTests/ChangeLog	2016-10-24 21:48:13 UTC (rev 207782)
@@ -1,3 +1,16 @@
+2016-10-24  Devin Rousso  <dcrousso+web...@gmail.com>
+
+        Web Inspector: Improve Quick Open sorting algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=163705
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/unit-tests/resource-query-controller-expected.txt:
+        * inspector/unit-tests/resource-query-controller.html:
+        Changed the ExecuteQueryGeneralRankings and ExecuteQueryPositionRankings tests to reflect
+        the new ranking logic.  Added ExecuteQueryConsecutiveRankings to test more realistic
+        scenarios and ensure better ranking.
+
 2016-10-24  Ryan Haddad  <ryanhad...@apple.com>
 
         Rebaseline tests for ios-simulator after r207757.

Modified: trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt (207781 => 207782)


--- trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt	2016-10-24 21:44:34 UTC (rev 207781)
+++ trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt	2016-10-24 21:48:13 UTC (rev 207782)
@@ -208,6 +208,9 @@
 -- Running test case: ExecuteQueryPositionRankings
 PASS: Results should be ranked by descending relevancy.
 
+-- Running test case: ExecuteQueryConsecutiveRankings
+PASS: Results should be ranked by descending relevancy.
+
 -- Running test case: GetMatchingTextRanges
 PASS: Result TextRanges should match the expected ranges.
 PASS: Result TextRanges should match the expected ranges.

Modified: trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html (207781 => 207782)


--- trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html	2016-10-24 21:44:34 UTC (rev 207781)
+++ trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html	2016-10-24 21:48:13 UTC (rev 207782)
@@ -10,7 +10,7 @@
     suite.addTestCase({
         name: "FindSpecialCharacterIndices",
         description: "Should correctly find special filename characters.",
-        test: function() {
+        test() {
             let matcher = new WebInspector.ResourceQueryController;
             let tests = [
                 {
@@ -69,7 +69,7 @@
     suite.addTestCase({
         name: "ExecuteQueryAgainstNoResources",
         description: "Should return no results if no resources were added to the controller.",
-        test: function() {
+        test() {
             let matcher = new WebInspector.ResourceQueryController;
             let results = matcher.executeQuery("abcde");
             InspectorTest.expectThat(!results.length, "Should return no results.")
@@ -79,7 +79,7 @@
     suite.addTestCase({
         name: "ExecuteWhitespaceQueryOrEmptyQuery",
         description: "Empty queries and queries containing only whitespace should return no results.",
-        test: function() {
+        test() {
             const whitespaceCharacters = " \t\r\n";
             let matcher = new WebInspector.ResourceQueryController;
             matcher.addResource(new WebInspector.Resource("abcde"));
@@ -97,7 +97,7 @@
     suite.addTestCase({
         name: "ExecuteQueryContainingWhitespace",
         description: "Whitespace within a query should be ignored.",
-        test: function() {
+        test() {
             let matcher = new WebInspector.ResourceQueryController;
             matcher.addResource(new WebInspector.Resource("abcde"));
 
@@ -111,7 +111,7 @@
     suite.addTestCase({
         name: "ExecuteQueryMatchNone",
         description: "Should not find a match.",
-        test: function() {
+        test() {
             let matcher = new WebInspector.ResourceQueryController;
             let tests = [
                 {query: "abcde", filename: "abcd"},
@@ -131,7 +131,7 @@
     suite.addTestCase({
         name: "ExecuteQueryMatchesExpectedCharacters",
         description: "Should match the expected query characters.",
-        test: function() {
+        test() {
             let matcher = new WebInspector.ResourceQueryController;
             let tests = [
                 {
@@ -222,7 +222,7 @@
     suite.addTestCase({
         name: "ExecuteQueryShouldIgnoreCase",
         description: "Queries that differ only in case should return identical results.",
-        test: function() {
+        test() {
             let matcher = new WebInspector.ResourceQueryController;
             let tests = [
                 {
@@ -270,8 +270,8 @@
     suite.addTestCase({
         name: "ExecuteQueryGeneralRankings",
         description: "Check that query results are ranked by descending relevance.",
-        test: function() {
-            let filenames = ["AxBxCxDxEx", "AbCdE", "AbcDe", "AxbcDe", "AxbxcDe", "abcde", "xabcde"]; // Filenames in order of descending rank.
+        test() {
+            let filenames = ["AbCdE", "AbcDe", "abcde", "AxbcDe", "AxBxCxDxEx", "AxbxcDe", "xabcde"]; // Filenames in order of descending rank.
             let matcher = new WebInspector.ResourceQueryController;
             filenames.forEach((filename) => matcher.addResource(new WebInspector.Resource(filename)));
 
@@ -285,8 +285,8 @@
     suite.addTestCase({
         name: "ExecuteQueryPositionRankings",
         description: "Check that matches close to the beginning of the filename rank higher.",
-        test: function() {
-            let filenames = ["BxCxDx", "AxBxCxDx", "xxxAxxxBxxxCxxxD", "bcd", "abcd"]; // Filenames in order of descending rank.
+        test() {
+            let filenames = ["bcd", "BxCxDx", "AxBxCxDx", "abcd", "xxxAxxxBxxxCxxxD"]; // Filenames in order of descending rank.
             let matcher = new WebInspector.ResourceQueryController;
             filenames.forEach((filename) => matcher.addResource(new WebInspector.Resource(filename)));
 
@@ -298,9 +298,44 @@
     });
 
     suite.addTestCase({
+        name: "ExecuteQueryConsecutiveRankings",
+        description: "Check that consecutive matches rank higher.",
+        test() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {
+                    filenames: ["Color.js", "HighlightColor.js", "CxxOxxLxxOxxR.js"],
+                    query: "color",
+                },
+                {
+                    filenames: ["ContentView.js", "CxxVxxIxxExxW.js"],
+                    query: "cview",
+                },
+                {
+                    filenames: ["HeapSnapshot.js", "HxxSxxHxxOxxT.js"],
+                    query: "hshot",
+                },
+            ];
+
+            let passed = true;
+            for (let {filenames, query} of tests) {
+                matcher.reset();
+                filenames.forEach((filename) => matcher.addResource(new WebInspector.Resource(filename)));
+
+                let results = matcher.executeQuery(query);
+                let resultFilenames = results.map((result) => result.resource.displayName);
+
+                passed = passed && Object.shallowEqual(resultFilenames, filenames);
+            }
+
+            InspectorTest.expectThat(passed, "Results should be ranked by descending relevancy.");
+        }
+    });
+
+    suite.addTestCase({
         name: "GetMatchingTextRanges",
         description: "Check that query result TextRanges are correct.",
-        test: function() {
+        test() {
             function textRange(start, end) {
                 return new WebInspector.TextRange(0, start, 0, end);
             }

Modified: trunk/Source/WebInspectorUI/ChangeLog (207781 => 207782)


--- trunk/Source/WebInspectorUI/ChangeLog	2016-10-24 21:44:34 UTC (rev 207781)
+++ trunk/Source/WebInspectorUI/ChangeLog	2016-10-24 21:48:13 UTC (rev 207782)
@@ -1,3 +1,17 @@
+2016-10-24  Devin Rousso  <dcrousso+web...@gmail.com>
+
+        Web Inspector: Improve Quick Open sorting algorithm
+        https://bugs.webkit.org/show_bug.cgi?id=163705
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Models/ResourceQueryResult.js:
+        (WebInspector.ResourceQueryResult.prototype._calculateRank.getMultiplier):
+        (WebInspector.ResourceQueryResult.prototype._calculateRank):
+        Added logic to multiply the ranking increment/decrement based on whether the current match
+        is part of a sequence, whether that sequence began with a special character, and the length
+        of the current sequence.
+
 2016-10-19  Dean Jackson  <d...@apple.com>
 
         Support CSS Shapes Level 1 without a prefix

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js (207781 => 207782)


--- trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js	2016-10-24 21:44:34 UTC (rev 207781)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js	2016-10-24 21:48:13 UTC (rev 207782)
@@ -61,23 +61,44 @@
 
     _calculateRank()
     {
-        const specialWeight = 50;
         const normalWeight = 10;
-        const consecutiveMatchWeight = 5;
+        const consecutiveWeight = 5;
+        const specialMultiplier = 5;
 
+        function getMultiplier(match) {
+            if (match.type === WebInspector.ResourceQueryMatch.Type.Special)
+                return specialMultiplier;
+
+            return 1;
+        }
+
         this._rank = 0;
 
         let previousMatch = null;
+        let consecutiveMatchStart = null;
         for (let match of this._matches) {
-            this._rank += match.type === WebInspector.ResourceQueryMatch.Type.Special ? specialWeight : normalWeight;
-            if (previousMatch && previousMatch.index === match.index - 1)
-                this._rank += consecutiveMatchWeight;
+            this._rank += normalWeight * getMultiplier(match);
 
+            let consecutive = previousMatch && previousMatch.index === match.index - 1;
+            if (consecutive) {
+                if (!consecutiveMatchStart)
+                    consecutiveMatchStart = previousMatch;
+
+                // If the first match in this consecutive series was a special character, give a
+                // bonus (more likely to match a specific word in the text).  Otherwise, multiply
+                // by the current length of the consecutive sequence (gives priority to fewer
+                // longer sequences instead of more short sequences).
+                this._rank += consecutiveWeight * getMultiplier(consecutiveMatchStart) * (match.index - consecutiveMatchStart.index);
+            } else if (consecutiveMatchStart)
+                consecutiveMatchStart = null;
+
             previousMatch = match;
 
-            // The match index is deducted from the total rank, so matches that
-            // occur closer to the beginning of the string are ranked higher.
-            this._rank -= match.index;
+            // The match index is deducted from the total rank, so matches that occur closer to
+            // the beginning of the string are ranked higher.  Increase the amount subtracted if
+            // the match is special, so as to favor matches towards the beginning of the string.
+            if (!consecutive)
+                this._rank -= match.index * getMultiplier(match);
         }
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to