PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: dart-lang/dartdoc (dart)

Issue:
Libraries ranked higher than classes in search results
Some users found it surprising that a library is ranked higher than classes of the same name. Here's an example:

<img width="580" alt="image" src="https://github.com/dart-lang/dartdoc/assets/348942/5903ebe9-c21e-4bf0-940f-5582435981b4">

It makes sense that developers are more likely to be looking up classes and methods than libraries. @srawlins pointed out it's done at https://github.com/dart-lang/dartdoc/blob/main/lib/src/search.dart#L176. Maybe we can revisit this heuristic.

Pull request:
Fixes #3436

Patch:
diff --git a/lib/src/search.dart b/lib/src/search.dart
index 3c62cc7f68..78d7ea9b84 100644
--- a/lib/src/search.dart
+++ b/lib/src/search.dart
@@ -153,27 +153,27 @@ class IndexItem {
   /// This is not the lexical scope of identifiers in Dart code, but similar in
   /// a very loose sense.
   int get _scope => switch (kind) {
-        // Root- and package-level items.
-        Kind.library => 0,
-        Kind.package => 0,
-        Kind.topic => 0,
-
         // Library members.
-        Kind.class_ => 1,
-        Kind.enum_ => 1,
-        Kind.extension => 1,
-        Kind.mixin => 1,
-        Kind.topLevelConstant => 1,
-        Kind.topLevelProperty => 1,
-        Kind.typedef => 1,
+        Kind.class_ => 0,
+        Kind.enum_ => 0,
+        Kind.extension => 0,
+        Kind.mixin => 0,
+        Kind.topLevelConstant => 0,
+        Kind.topLevelProperty => 0,
+        Kind.typedef => 0,
 
         // Container members.
-        Kind.accessor => 2,
-        Kind.constant => 2,
-        Kind.constructor => 2,
-        Kind.function => 2,
-        Kind.method => 2,
-        Kind.property => 2,
+        Kind.accessor => 1,
+        Kind.constant => 1,
+        Kind.constructor => 1,
+        Kind.function => 1,
+        Kind.method => 1,
+        Kind.property => 1,
+
+        // Root- and package-level items.
+        Kind.library => 2,
+        Kind.package => 2,
+        Kind.topic => 2,
 
         // Others.
         Kind.dynamic => 3,


Test patch:
diff --git a/test/search_test.dart b/test/search_test.dart
index 08ea141d5a..ffdc7870b8 100644
--- a/test/search_test.dart
+++ b/test/search_test.dart
@@ -106,7 +106,7 @@ class SearchTest {
   void test_prefersHigherPackages() {
     expect(
       matchNames('foo'),
-      containsAllInOrder(['FOO', 'foo.FOO', 'foo', 'foo.Foo']),
+      containsAllInOrder(['foo.FOO', 'FOO', 'foo.Foo', 'foo']),
     );
   }
 
@@ -119,10 +119,10 @@ class SearchTest {
     );
   }
 
-  void test_prefersOuterScopes() {
+  void test_prefersLibraryScoped() {
     expect(
       matchNames('foo'),
-      containsAllInOrder(['foo', 'foo.Foo', 'bar.Bar.foo']),
+      containsAllInOrder(['foo.Foo', 'bar.Bar.foo', 'foo']),
     );
   }