<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[207782] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/207782">207782</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-10-24 14:48:13 -0700 (Mon, 24 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Improve Quick Open sorting algorithm
https://bugs.webkit.org/show_bug.cgi?id=163705

Patch by Devin Rousso &lt;dcrousso+webkit@gmail.com&gt; 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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorunittestsresourcequerycontrollerexpectedtxt">trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorunittestsresourcequerycontrollerhtml">trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsResourceQueryResultjs">trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (207781 => 207782)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-10-24 21:44:34 UTC (rev 207781)
+++ trunk/LayoutTests/ChangeLog        2016-10-24 21:48:13 UTC (rev 207782)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-10-24  Devin Rousso  &lt;dcrousso+webkit@gmail.com&gt;
+
+        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.
+
</ins><span class="cx"> 2016-10-24  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Rebaseline tests for ios-simulator after r207757.
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunittestsresourcequerycontrollerexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/resource-query-controller-expected.txt (207781 => 207782)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -208,6 +208,9 @@
</span><span class="cx"> -- Running test case: ExecuteQueryPositionRankings
</span><span class="cx"> PASS: Results should be ranked by descending relevancy.
</span><span class="cx"> 
</span><ins>+-- Running test case: ExecuteQueryConsecutiveRankings
+PASS: Results should be ranked by descending relevancy.
+
</ins><span class="cx"> -- Running test case: GetMatchingTextRanges
</span><span class="cx"> PASS: Result TextRanges should match the expected ranges.
</span><span class="cx"> PASS: Result TextRanges should match the expected ranges.
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorunittestsresourcequerycontrollerhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/unit-tests/resource-query-controller.html (207781 => 207782)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -10,7 +10,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;FindSpecialCharacterIndices&quot;,
</span><span class="cx">         description: &quot;Should correctly find special filename characters.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             let tests = [
</span><span class="cx">                 {
</span><span class="lines">@@ -69,7 +69,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryAgainstNoResources&quot;,
</span><span class="cx">         description: &quot;Should return no results if no resources were added to the controller.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             let results = matcher.executeQuery(&quot;abcde&quot;);
</span><span class="cx">             InspectorTest.expectThat(!results.length, &quot;Should return no results.&quot;)
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteWhitespaceQueryOrEmptyQuery&quot;,
</span><span class="cx">         description: &quot;Empty queries and queries containing only whitespace should return no results.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             const whitespaceCharacters = &quot; \t\r\n&quot;;
</span><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             matcher.addResource(new WebInspector.Resource(&quot;abcde&quot;));
</span><span class="lines">@@ -97,7 +97,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryContainingWhitespace&quot;,
</span><span class="cx">         description: &quot;Whitespace within a query should be ignored.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             matcher.addResource(new WebInspector.Resource(&quot;abcde&quot;));
</span><span class="cx"> 
</span><span class="lines">@@ -111,7 +111,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryMatchNone&quot;,
</span><span class="cx">         description: &quot;Should not find a match.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             let tests = [
</span><span class="cx">                 {query: &quot;abcde&quot;, filename: &quot;abcd&quot;},
</span><span class="lines">@@ -131,7 +131,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryMatchesExpectedCharacters&quot;,
</span><span class="cx">         description: &quot;Should match the expected query characters.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             let tests = [
</span><span class="cx">                 {
</span><span class="lines">@@ -222,7 +222,7 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryShouldIgnoreCase&quot;,
</span><span class="cx">         description: &quot;Queries that differ only in case should return identical results.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             let tests = [
</span><span class="cx">                 {
</span><span class="lines">@@ -270,8 +270,8 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryGeneralRankings&quot;,
</span><span class="cx">         description: &quot;Check that query results are ranked by descending relevance.&quot;,
</span><del>-        test: function() {
-            let filenames = [&quot;AxBxCxDxEx&quot;, &quot;AbCdE&quot;, &quot;AbcDe&quot;, &quot;AxbcDe&quot;, &quot;AxbxcDe&quot;, &quot;abcde&quot;, &quot;xabcde&quot;]; // Filenames in order of descending rank.
</del><ins>+        test() {
+            let filenames = [&quot;AbCdE&quot;, &quot;AbcDe&quot;, &quot;abcde&quot;, &quot;AxbcDe&quot;, &quot;AxBxCxDxEx&quot;, &quot;AxbxcDe&quot;, &quot;xabcde&quot;]; // Filenames in order of descending rank.
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             filenames.forEach((filename) =&gt; matcher.addResource(new WebInspector.Resource(filename)));
</span><span class="cx"> 
</span><span class="lines">@@ -285,8 +285,8 @@
</span><span class="cx">     suite.addTestCase({
</span><span class="cx">         name: &quot;ExecuteQueryPositionRankings&quot;,
</span><span class="cx">         description: &quot;Check that matches close to the beginning of the filename rank higher.&quot;,
</span><del>-        test: function() {
-            let filenames = [&quot;BxCxDx&quot;, &quot;AxBxCxDx&quot;, &quot;xxxAxxxBxxxCxxxD&quot;, &quot;bcd&quot;, &quot;abcd&quot;]; // Filenames in order of descending rank.
</del><ins>+        test() {
+            let filenames = [&quot;bcd&quot;, &quot;BxCxDx&quot;, &quot;AxBxCxDx&quot;, &quot;abcd&quot;, &quot;xxxAxxxBxxxCxxxD&quot;]; // Filenames in order of descending rank.
</ins><span class="cx">             let matcher = new WebInspector.ResourceQueryController;
</span><span class="cx">             filenames.forEach((filename) =&gt; matcher.addResource(new WebInspector.Resource(filename)));
</span><span class="cx"> 
</span><span class="lines">@@ -298,9 +298,44 @@
</span><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     suite.addTestCase({
</span><ins>+        name: &quot;ExecuteQueryConsecutiveRankings&quot;,
+        description: &quot;Check that consecutive matches rank higher.&quot;,
+        test() {
+            let matcher = new WebInspector.ResourceQueryController;
+            let tests = [
+                {
+                    filenames: [&quot;Color.js&quot;, &quot;HighlightColor.js&quot;, &quot;CxxOxxLxxOxxR.js&quot;],
+                    query: &quot;color&quot;,
+                },
+                {
+                    filenames: [&quot;ContentView.js&quot;, &quot;CxxVxxIxxExxW.js&quot;],
+                    query: &quot;cview&quot;,
+                },
+                {
+                    filenames: [&quot;HeapSnapshot.js&quot;, &quot;HxxSxxHxxOxxT.js&quot;],
+                    query: &quot;hshot&quot;,
+                },
+            ];
+
+            let passed = true;
+            for (let {filenames, query} of tests) {
+                matcher.reset();
+                filenames.forEach((filename) =&gt; matcher.addResource(new WebInspector.Resource(filename)));
+
+                let results = matcher.executeQuery(query);
+                let resultFilenames = results.map((result) =&gt; result.resource.displayName);
+
+                passed = passed &amp;&amp; Object.shallowEqual(resultFilenames, filenames);
+            }
+
+            InspectorTest.expectThat(passed, &quot;Results should be ranked by descending relevancy.&quot;);
+        }
+    });
+
+    suite.addTestCase({
</ins><span class="cx">         name: &quot;GetMatchingTextRanges&quot;,
</span><span class="cx">         description: &quot;Check that query result TextRanges are correct.&quot;,
</span><del>-        test: function() {
</del><ins>+        test() {
</ins><span class="cx">             function textRange(start, end) {
</span><span class="cx">                 return new WebInspector.TextRange(0, start, 0, end);
</span><span class="cx">             }
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (207781 => 207782)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-10-24  Devin Rousso  &lt;dcrousso+webkit@gmail.com&gt;
+
+        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.
+
</ins><span class="cx"> 2016-10-19  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Support CSS Shapes Level 1 without a prefix
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsResourceQueryResultjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ResourceQueryResult.js (207781 => 207782)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -61,23 +61,44 @@
</span><span class="cx"> 
</span><span class="cx">     _calculateRank()
</span><span class="cx">     {
</span><del>-        const specialWeight = 50;
</del><span class="cx">         const normalWeight = 10;
</span><del>-        const consecutiveMatchWeight = 5;
</del><ins>+        const consecutiveWeight = 5;
+        const specialMultiplier = 5;
</ins><span class="cx"> 
</span><ins>+        function getMultiplier(match) {
+            if (match.type === WebInspector.ResourceQueryMatch.Type.Special)
+                return specialMultiplier;
+
+            return 1;
+        }
+
</ins><span class="cx">         this._rank = 0;
</span><span class="cx"> 
</span><span class="cx">         let previousMatch = null;
</span><ins>+        let consecutiveMatchStart = null;
</ins><span class="cx">         for (let match of this._matches) {
</span><del>-            this._rank += match.type === WebInspector.ResourceQueryMatch.Type.Special ? specialWeight : normalWeight;
-            if (previousMatch &amp;&amp; previousMatch.index === match.index - 1)
-                this._rank += consecutiveMatchWeight;
</del><ins>+            this._rank += normalWeight * getMultiplier(match);
</ins><span class="cx"> 
</span><ins>+            let consecutive = previousMatch &amp;&amp; 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;
+
</ins><span class="cx">             previousMatch = match;
</span><span class="cx"> 
</span><del>-            // 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;
</del><ins>+            // 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);
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>