Skip to content

Commit 01421ba

Browse files
committed
Better scoring & faster debounce
1 parent cb6ef8a commit 01421ba

File tree

5 files changed

+111
-111
lines changed

5 files changed

+111
-111
lines changed

project/Build.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ object DottyJSPlugin extends AutoPlugin {
8080
object Build {
8181
import ScaladocConfigs._
8282

83-
val referenceVersion = "3.2.0"
83+
val referenceVersion = "3.2.1-RC1"
8484

85-
val baseVersion = "3.2.1-RC1"
85+
val baseVersion = "3.2.2-RC1"
8686

8787
// Versions used by the vscode extension to create a new project
8888
// This should be the latest published releases.

scaladoc-js/main/src/searchbar/SearchbarComponent.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class SearchbarComponent(engine: PageSearchEngine, inkuireEngine: InkuireJSSearc
189189
resultsDiv.scrollTop = 0
190190
resultsDiv.onscroll = (event: Event) => { }
191191
val fragment = document.createDocumentFragment()
192-
timeoutHandle = setTimeout(600.millisecond) {
192+
timeoutHandle = setTimeout(300.millisecond) {
193193
clearResults()
194194
handleRecentQueries(query)
195195
parser.parse(query) match {

scaladoc-js/main/src/searchbar/engine/PageSearchEngine.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import scala.annotation.tailrec
2020
class PageSearchEngine(pages: List[PageEntry]):
2121

2222
def query(query: NameAndKindQuery): Future[List[MatchResult]] = Future {
23-
val time = System.currentTimeMillis()
2423
matchPages(query)
2524
.filter {
2625
case MatchResult(score, _, _) => score >= 0
@@ -41,7 +40,8 @@ class PageSearchEngine(pages: List[PageEntry]):
4140
private val positionScores = List(8,4,2,1).orElse(PartialFunction.fromFunction(_ => 0))
4241

4342
private def matchCompletnessBonus(nameCharacters: Int, matchCharacters: Int): Int =
44-
(matchCharacters * 3) / nameCharacters
43+
(matchCharacters * 6) / nameCharacters +
44+
(if nameCharacters == matchCharacters then 2 else 0)
4545

4646
private def matchPages(query: NameAndKindQuery): List[MatchResult] = query match
4747
case NameAndKindQuery(None, None) => List.empty

scaladoc-js/main/test/dotty/tools/scaladoc/MatchersTest.scala

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,80 @@ import org.junit.{Test, Assert}
44
import org.junit.Assert._
55

66
class MatchersTest
7-
// private val kinds = Seq(
8-
// "class",
9-
// "trait",
10-
// "enum",
11-
// "object",
12-
// "def",
13-
// "val",
14-
// "var",
15-
// "package",
16-
// "given",
17-
// "type"
18-
// )
19-
// private val names = Seq(
20-
// "NullPointerException",
21-
// "NPException",
22-
// "Seq",
23-
// "SeqOps",
24-
// "writeBytes",
25-
// "lessOrEqual",
26-
// "testFuzzySearch1",
27-
// "testF",
28-
// "testFS"
29-
// )
30-
// private val pages = for {
31-
// kind <- kinds
32-
// name <- names
33-
// } yield
34-
// PageEntry(
35-
// s"$kind $name",
36-
// "",
37-
// "",
38-
// "",
39-
// false,
40-
// s"$name",
41-
// kind,
42-
// StringUtils.createCamelCaseTokens(name)
43-
// )
44-
//
45-
// private def result(matchers: List[Matchers]) = {
46-
// pages.map { p =>
47-
// p -> matchers.map(_(p))
48-
// }.filterNot { (page, results) =>
49-
// results.exists(r => r.priority == -1)
50-
// }.map((page, results) => page)
51-
// }
52-
//
53-
// @Test
54-
// def testByKind = kinds.foreach { kind =>
55-
// val res = result(List(ByKind(kind)))
56-
// val expected = pages.filter(p => p.fullName.startsWith(kind)).toSet
57-
// assertEquals(
58-
// s"Matchers test error: for kind: $kind should match $expected but matched $res",
59-
// expected,
60-
// res.toSet
61-
// )
62-
// }
63-
//
64-
// private def byNameTestCase(query: String, expectedMatch: String*) = expectedMatch.foreach { expMatch =>
65-
// assertTrue(
66-
// s"Matchers test error: for query: $query expected $expMatch",
67-
// result(List(ByName(query))).exists(p => p.shortName.contains(expMatch))
68-
// )
69-
// }
70-
//
71-
// @Test
72-
// def testByName = {
73-
// names.foreach(n => byNameTestCase(n, n))
74-
// byNameTestCase("NPE", "NPException", "NullPointerException")
75-
// byNameTestCase("NullPE", "NullPointerException")
76-
// byNameTestCase("tFuzzS", "testFuzzySearch1")
77-
// byNameTestCase("SO", "SeqOps")
78-
// byNameTestCase("teFS", "testFS")
79-
// byNameTestCase("writeBy", "writeBytes")
80-
// byNameTestCase("seQ", "Seq")
81-
// byNameTestCase("lOrEqu", "lessOrEqual")
82-
// byNameTestCase("teF", "testFS", "testF")
83-
// }
7+
private val kinds = Seq(
8+
"class",
9+
"trait",
10+
"enum",
11+
"object",
12+
"def",
13+
"val",
14+
"var",
15+
"package",
16+
"given",
17+
"type"
18+
)
19+
private val names = Seq(
20+
"NullPointerException",
21+
"NPException",
22+
"Seq",
23+
"SeqOps",
24+
"writeBytes",
25+
"lessOrEqual",
26+
"testFuzzySearch1",
27+
"testF",
28+
"testFS"
29+
)
30+
private val pages = for {
31+
kind <- kinds
32+
name <- names
33+
} yield
34+
PageEntry(
35+
s"$kind $name",
36+
"",
37+
"",
38+
"",
39+
false,
40+
s"$name",
41+
kind,
42+
StringUtils.createCamelCaseTokens(name)
43+
)
44+
45+
private def result(matchers: List[Matchers]) = {
46+
pages.map { p =>
47+
p -> matchers.map(_(p))
48+
}.filterNot { (page, results) =>
49+
results.exists(r => r.priority == -1)
50+
}.map((page, results) => page)
51+
}
52+
53+
@Test
54+
def testByKind = kinds.foreach { kind =>
55+
val res = result(List(ByKind(kind)))
56+
val expected = pages.filter(p => p.fullName.startsWith(kind)).toSet
57+
assertEquals(
58+
s"Matchers test error: for kind: $kind should match $expected but matched $res",
59+
expected,
60+
res.toSet
61+
)
62+
}
63+
64+
private def byNameTestCase(query: String, expectedMatch: String*) = expectedMatch.foreach { expMatch =>
65+
assertTrue(
66+
s"Matchers test error: for query: $query expected $expMatch",
67+
result(List(ByName(query))).exists(p => p.shortName.contains(expMatch))
68+
)
69+
}
70+
71+
@Test
72+
def testByName = {
73+
names.foreach(n => byNameTestCase(n, n))
74+
byNameTestCase("NPE", "NPException", "NullPointerException")
75+
byNameTestCase("NullPE", "NullPointerException")
76+
byNameTestCase("tFuzzS", "testFuzzySearch1")
77+
byNameTestCase("SO", "SeqOps")
78+
byNameTestCase("teFS", "testFS")
79+
byNameTestCase("writeBy", "writeBytes")
80+
byNameTestCase("seQ", "Seq")
81+
byNameTestCase("lOrEqu", "lessOrEqual")
82+
byNameTestCase("teF", "testFS", "testF")
83+
}

scaladoc-js/main/test/dotty/tools/scaladoc/QueryParserTest.scala

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@ import org.junit.{Test, Assert}
44
import org.junit.Assert._
55

66
class QueryParserTest
7-
// val queryParser = QueryParser()
8-
// val kinds = Seq(
9-
// "class",
10-
// "trait",
11-
// "enum",
12-
// "object",
13-
// "def",
14-
// "val",
15-
// "var",
16-
// "package",
17-
// "given",
18-
// "type"
19-
// )
20-
// private def testCase(query: String, result: EngineQuery) = {
21-
// val parsed = queryParser.parse(query)
22-
// assertEquals(
23-
// s"Query parser test error: for query: $query expected $result but found $parsed",
24-
// parsed,
25-
// result
26-
// )
27-
// }
28-
//
29-
// @Test
30-
// def queryParserTests() = {
31-
// kinds.foreach(k => testCase(s"$k ", NameAndKindQuery(List(ByKind(k), ByName("")))))
32-
// testCase("trait", NameAndKindQuery(List(ByName("trait"))))
33-
// testCase("trait A", NameAndKindQuery(List(ByKind("trait"), ByName("A"))))
34-
// testCase("`trait A`", NameAndKindQuery(List(ByName("trait A"))))
35-
// }
7+
val queryParser = QueryParser()
8+
val kinds = Seq(
9+
"class",
10+
"trait",
11+
"enum",
12+
"object",
13+
"def",
14+
"val",
15+
"var",
16+
"package",
17+
"given",
18+
"type"
19+
)
20+
private def testCase(query: String, result: EngineQuery) = {
21+
val parsed = queryParser.parse(query)
22+
assertEquals(
23+
s"Query parser test error: for query: $query expected $result but found $parsed",
24+
parsed,
25+
result
26+
)
27+
}
28+
29+
@Test
30+
def queryParserTests() = {
31+
kinds.foreach(k => testCase(s"$k ", NameAndKindQuery(List(ByKind(k), ByName("")))))
32+
testCase("trait", NameAndKindQuery(None, Some("trait")))
33+
testCase("trait A", NameAndKindQuery(Some("A"), Some("trait")))
34+
testCase("`trait A`", NameAndKindQuery(Some("trait A"), None))
35+
}

0 commit comments

Comments
 (0)