@@ -42,11 +42,12 @@ class SearchAdapter {
4242 return SearchResultPage (
4343 form,
4444 result.totalCount,
45+ nameMatches: result.nameMatches,
4546 sdkLibraryHits: result.sdkLibraryHits,
4647 packageHits:
4748 result.packageHits.map ((h) => views[h.package]).nonNulls.toList (),
4849 errorMessage: result.errorMessage,
49- statusCode: result.statusCode,
50+ statusCode: result.statusCode ?? 200 ,
5051 );
5152 }
5253
@@ -84,8 +85,10 @@ class SearchAdapter {
8485 Future <PackageSearchResult > _fallbackSearch (SearchForm form) async {
8586 // Some search queries must not be served with the fallback search.
8687 if (form.parsedQuery.tagsPredicate.isNotEmpty) {
87- return PackageSearchResult .empty (
88- errorMessage: 'Search is temporarily unavailable.' );
88+ return PackageSearchResult .error (
89+ errorMessage: 'Search is temporarily unavailable.' ,
90+ statusCode: 503 ,
91+ );
8992 }
9093
9194 final names = await nameTracker
@@ -108,11 +111,13 @@ class SearchAdapter {
108111 packageHits =
109112 packageHits.skip (form.offset).take (form.pageSize ?? 10 ).toList ();
110113 return PackageSearchResult (
111- timestamp: clock.now ().toUtc (),
112- packageHits: packageHits,
113- totalCount: totalCount,
114- errorMessage:
115- 'Search is temporarily impaired, filtering and ranking may be incorrect.' );
114+ timestamp: clock.now ().toUtc (),
115+ packageHits: packageHits,
116+ totalCount: totalCount,
117+ errorMessage:
118+ 'Search is temporarily impaired, filtering and ranking may be incorrect.' ,
119+ statusCode: 503 ,
120+ );
116121 }
117122
118123 Future <Map <String , PackageView >> _getPackageViewsFromHits (
@@ -137,6 +142,11 @@ class SearchResultPage {
137142 /// The total number of results available for the search.
138143 final int totalCount;
139144
145+ /// Package names that are exact name matches or close to (e.g. names that
146+ /// would be considered as blocker for publishing).
147+ final List <String >? nameMatches;
148+
149+ /// The hits from the SDK libraries.
140150 final List <SdkLibraryHit > sdkLibraryHits;
141151
142152 /// The current list of packages on the page.
@@ -146,24 +156,20 @@ class SearchResultPage {
146156 /// the query was not processed entirely.
147157 final String ? errorMessage;
148158
149- /// The non-200 status code that will be used to render the [errorMessage] .
150- final int ? statusCode;
159+ /// The code that will be used to render the page .
160+ final int statusCode;
151161
152162 SearchResultPage (
153163 this .form,
154164 this .totalCount, {
165+ this .nameMatches,
155166 List <SdkLibraryHit >? sdkLibraryHits,
156167 List <PackageView >? packageHits,
157168 this .errorMessage,
158- this .statusCode,
169+ this .statusCode = 200 ,
159170 }) : sdkLibraryHits = sdkLibraryHits ?? < SdkLibraryHit > [],
160171 packageHits = packageHits ?? < PackageView > [];
161172
162- SearchResultPage .empty (this .form, {this .errorMessage, this .statusCode})
163- : totalCount = 0 ,
164- sdkLibraryHits = < SdkLibraryHit > [],
165- packageHits = [];
166-
167173 bool get hasNoHit => sdkLibraryHits.isEmpty && packageHits.isEmpty;
168174 bool get hasHit => ! hasNoHit;
169175}
0 commit comments