From a80f2cb883e493e31c57cb964ec0e12855dd6cc7 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Fri, 29 Aug 2025 17:30:48 +0200 Subject: [PATCH] Handle empty packages list in search (empty results). --- app/lib/search/mem_index.dart | 2 +- app/lib/search/search_service.dart | 3 ++- pkg/_pub_shared/lib/search/search_request_data.dart | 5 ++--- pkg/pub_integration/test/like_test.dart | 11 ++++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/lib/search/mem_index.dart b/app/lib/search/mem_index.dart index 8dd00a3a7c..2c01406bfc 100644 --- a/app/lib/search/mem_index.dart +++ b/app/lib/search/mem_index.dart @@ -345,7 +345,7 @@ class InMemoryPackageIndex { /// The [BitArrayPool] does not reset the reused pool items, because initialization /// depends on the presence of the [filterOnPackages] list. void _resetBitArray(BitArray selected, List? filterOnPackages) { - if (filterOnPackages != null && filterOnPackages.isNotEmpty) { + if (filterOnPackages != null) { selected.clearAll(); for (final package in filterOnPackages) { final index = _nameToIndex[package]; diff --git a/app/lib/search/search_service.dart b/app/lib/search/search_service.dart index dc19b40fa5..d7a80dcc83 100644 --- a/app/lib/search/search_service.dart +++ b/app/lib/search/search_service.dart @@ -237,7 +237,8 @@ class ServiceSearchQuery { isNaturalOrder && _hasNoOwnershipScope && !_isFlutterFavorite && - (textMatchExtent ?? TextMatchExtent.api).shouldMatchApi(); + (textMatchExtent ?? TextMatchExtent.api).shouldMatchApi() && + packages == null; /// Returns the validity status of the query. QueryValidity evaluateValidity() { diff --git a/pkg/_pub_shared/lib/search/search_request_data.dart b/pkg/_pub_shared/lib/search/search_request_data.dart index 989348afa2..dfa0eca035 100644 --- a/pkg/_pub_shared/lib/search/search_request_data.dart +++ b/pkg/_pub_shared/lib/search/search_request_data.dart @@ -28,10 +28,9 @@ class SearchRequestData { this.offset, this.limit, this.textMatchExtent, - List? packages, + this.packages, }) : query = _trimToNull(query), - publisherId = _trimToNull(publisherId), - packages = packages != null && packages.isNotEmpty ? packages : null; + publisherId = _trimToNull(publisherId); factory SearchRequestData.fromJson(Map json) => _$SearchRequestDataFromJson(json); diff --git a/pkg/pub_integration/test/like_test.dart b/pkg/pub_integration/test/like_test.dart index 017d61e1db..a19899e48b 100644 --- a/pkg/pub_integration/test/like_test.dart +++ b/pkg/pub_integration/test/like_test.dart @@ -74,6 +74,11 @@ void main() { await page.gotoOrigin('/experimental?my-liked-search=1'); + // checking search with my-liked packages - without any likes + await page.gotoOrigin('/packages?q=pkg+is:liked-by-me'); + final info1 = await listingPageInfo(page); + expect(info1.packageNames, isEmpty); + await page.gotoOrigin('/packages/test_pkg'); expect(await getCountLabels(), ['0', '0', '']); @@ -81,10 +86,10 @@ void main() { await Future.delayed(Duration(seconds: 1)); expect(await getCountLabels(), ['1', '1', '']); - // checking search with my-liked packages + // checking search with my-liked packages - with the one liked package await page.gotoOrigin('/packages?q=pkg+is:liked-by-me'); - final info = await listingPageInfo(page); - expect(info.packageNames.toSet(), {'test_pkg'}); + final info2 = await listingPageInfo(page); + expect(info2.packageNames.toSet(), {'test_pkg'}); // displaying all three await page.gotoOrigin('/packages/test_pkg/score');