@@ -8,6 +8,7 @@ import 'dart:math' show max;
88import 'package:_pub_shared/search/search_form.dart' ;
99import 'package:_pub_shared/search/tags.dart' ;
1010import 'package:clock/clock.dart' ;
11+ import 'package:collection/collection.dart' ;
1112import 'package:json_annotation/json_annotation.dart' ;
1213import 'package:pub_dev/shared/utils.dart' ;
1314
@@ -166,7 +167,7 @@ class ServiceSearchQuery {
166167 final int ? limit;
167168
168169 /// The scope/depth of text matching.
169- final int ? textMatchExtent;
170+ final TextMatchExtent ? textMatchExtent;
170171
171172 ServiceSearchQuery ._({
172173 this .query,
@@ -189,7 +190,7 @@ class ServiceSearchQuery {
189190 int ? minPoints,
190191 int offset = 0 ,
191192 int ? limit = 10 ,
192- int ? textMatchExtent,
193+ TextMatchExtent ? textMatchExtent,
193194 }) {
194195 final q = query? .trimToNull ();
195196 return ServiceSearchQuery ._(
@@ -216,8 +217,10 @@ class ServiceSearchQuery {
216217 int .tryParse (uri.queryParameters['minPoints' ] ?? '0' ) ?? 0 ;
217218 final offset = int .tryParse (uri.queryParameters['offset' ] ?? '0' ) ?? 0 ;
218219 final limit = int .tryParse (uri.queryParameters['limit' ] ?? '0' ) ?? 0 ;
219- final textMatchExtent =
220- int .tryParse (uri.queryParameters['textMatchExtent' ] ?? '' );
220+ final textMatchExtentValue =
221+ uri.queryParameters['textMatchExtent' ]? .trim () ?? '' ;
222+ final textMatchExtent = TextMatchExtent .values
223+ .firstWhereOrNull ((e) => e.name == textMatchExtentValue);
221224
222225 return ServiceSearchQuery .parse (
223226 query: q,
@@ -238,7 +241,7 @@ class ServiceSearchQuery {
238241 SearchOrder ? order,
239242 int ? offset,
240243 int ? limit,
241- int ? textMatchExtent,
244+ TextMatchExtent ? textMatchExtent,
242245 }) {
243246 return ServiceSearchQuery ._(
244247 query: query ?? this .query,
@@ -262,8 +265,7 @@ class ServiceSearchQuery {
262265 'minPoints' : minPoints.toString (),
263266 'limit' : limit? .toString (),
264267 'order' : order? .name,
265- if (textMatchExtent != null )
266- 'textMatchExtent' : textMatchExtent.toString (),
268+ if (textMatchExtent != null ) 'textMatchExtent' : textMatchExtent! .name,
267269 };
268270 map.removeWhere ((k, v) => v == null );
269271 return map;
@@ -291,7 +293,7 @@ class ServiceSearchQuery {
291293 _isNaturalOrder &&
292294 _hasNoOwnershipScope &&
293295 ! _isFlutterFavorite &&
294- TextMatchExtent .shouldMatchApi (textMatchExtent );
296+ (textMatchExtent ?? TextMatchExtent .api). shouldMatchApi ();
295297
296298 bool get considerHighlightedHit => _hasOnlyFreeText && _hasNoOwnershipScope;
297299 bool get includeHighlightedHit => considerHighlightedHit && offset == 0 ;
@@ -310,38 +312,35 @@ class ServiceSearchQuery {
310312}
311313
312314/// The scope (depth) of the text matching.
313- abstract class TextMatchExtent {
315+ enum TextMatchExtent {
314316 /// No text search is done.
315317 /// Requests with text queries will return a failure message.
316- static final int none = 10 ;
318+ none,
317319
318320 /// Text search is on package names.
319- static final int name = 20 ;
321+ name,
320322
321323 /// Text search is on package names, descriptions and topic tags.
322- static final int description = 30 ;
324+ description,
323325
324326 /// Text search is on names, descriptions, topic tags and readme content.
325- static final int readme = 40 ;
327+ readme,
326328
327329 /// Text search is on names, descriptions, topic tags, readme content and API symbols.
328- static final int api = 50 ;
329-
330- /// No value was given, assuming default behavior of including everything.
331- static final int unspecified = 99 ;
330+ api,
331+ ;
332332
333333 /// Text search is on package names.
334- static bool shouldMatchName (int ? value ) => (value ?? unspecified) >= name;
334+ bool shouldMatchName () => index >= name.index ;
335335
336336 /// Text search is on package names, descriptions and topic tags.
337- static bool shouldMatchDescription (int ? value) =>
338- (value ?? unspecified) >= description;
337+ bool shouldMatchDescription () => index >= description.index;
339338
340339 /// Text search is on names, descriptions, topic tags and readme content.
341- static bool shouldMatchReadme (int ? value ) => (value ?? unspecified) >= readme;
340+ bool shouldMatchReadme () => index >= readme.index ;
342341
343342 /// Text search is on names, descriptions, topic tags, readme content and API symbols.
344- static bool shouldMatchApi (int ? value ) => (value ?? unspecified) >= api;
343+ bool shouldMatchApi () => index >= api.index ;
345344}
346345
347346class QueryValidity {
0 commit comments