Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/lib/search/mem_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,11 @@ class PackageNameIndex {

/// Returns the list of package names where the collapsed name matches.
List<String>? lookupMatchingNames(String text) {
return _collapsedNameResolvesToMap[_removeUnderscores(text.toLowerCase())];
// convert to lowercase, remove spaces and underscores
final collapsedName = _removeUnderscores(
text.toLowerCase().replaceAll(' ', ''),
);
return _collapsedNameResolvesToMap[collapsedName];
}
}

Expand Down
38 changes: 38 additions & 0 deletions app/test/search/mem_index_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,44 @@ server.dart adds a small, prescriptive server (PicoServer) that can be configure
},
);
});

test('exact name match with multi-phrase query', () {
final index = InMemoryPackageIndex(
documents: [
PackageDocument(
package: 'abc_def_xyz',
description: 'abc def xyz',
maxPoints: 100,
grantedPoints: 100,
tags: ['sdk:dart', 'sdk:flutter'],
likeCount: 400,
downloadCount: 400,
),

PackageDocument(
package: 'abc_def',
description: 'some package',
maxPoints: 100,
grantedPoints: 0,
tags: ['sdk:dart', 'sdk:flutter'],
likeCount: 4,
downloadCount: 4,
),
],
);

final rs = index.search(ServiceSearchQuery.parse(query: 'abc def'));
expect(rs.toJson(), {
'timestamp': isNotEmpty,
'totalCount': 2,
'nameMatches': ['abc_def'],
'sdkLibraryHits': [],
'packageHits': [
{'package': 'abc_def', 'score': closeTo(0.55, 0.01)},
{'package': 'abc_def_xyz', 'score': closeTo(1.0, 0.01)},
],
});
});
});
});

Expand Down