Skip to content

Commit 14b1fca

Browse files
authored
Fix exact name matching in multi-phrase search queries. (#8991)
1 parent 1677f46 commit 14b1fca

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/lib/search/mem_index.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,11 @@ class PackageNameIndex {
757757

758758
/// Returns the list of package names where the collapsed name matches.
759759
List<String>? lookupMatchingNames(String text) {
760-
return _collapsedNameResolvesToMap[_removeUnderscores(text.toLowerCase())];
760+
// convert to lowercase, remove spaces and underscores
761+
final collapsedName = _removeUnderscores(
762+
text.toLowerCase().replaceAll(' ', ''),
763+
);
764+
return _collapsedNameResolvesToMap[collapsedName];
761765
}
762766
}
763767

app/test/search/mem_index_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,44 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
742742
},
743743
);
744744
});
745+
746+
test('exact name match with multi-phrase query', () {
747+
final index = InMemoryPackageIndex(
748+
documents: [
749+
PackageDocument(
750+
package: 'abc_def_xyz',
751+
description: 'abc def xyz',
752+
maxPoints: 100,
753+
grantedPoints: 100,
754+
tags: ['sdk:dart', 'sdk:flutter'],
755+
likeCount: 400,
756+
downloadCount: 400,
757+
),
758+
759+
PackageDocument(
760+
package: 'abc_def',
761+
description: 'some package',
762+
maxPoints: 100,
763+
grantedPoints: 0,
764+
tags: ['sdk:dart', 'sdk:flutter'],
765+
likeCount: 4,
766+
downloadCount: 4,
767+
),
768+
],
769+
);
770+
771+
final rs = index.search(ServiceSearchQuery.parse(query: 'abc def'));
772+
expect(rs.toJson(), {
773+
'timestamp': isNotEmpty,
774+
'totalCount': 2,
775+
'nameMatches': ['abc_def'],
776+
'sdkLibraryHits': [],
777+
'packageHits': [
778+
{'package': 'abc_def', 'score': closeTo(0.55, 0.01)},
779+
{'package': 'abc_def_xyz', 'score': closeTo(1.0, 0.01)},
780+
],
781+
});
782+
});
745783
});
746784
});
747785

0 commit comments

Comments
 (0)