@@ -19,16 +19,14 @@ import 'package:meta/meta.dart';
1919// ignore: implementation_imports
2020import 'package:pana/src/dartdoc/pub_dartdoc_data.dart' ;
2121import 'package:pool/pool.dart' ;
22- import 'package:pub_dev/publisher/backend.dart' ;
23-
24- import 'package:pub_dev/search/search_client.dart' ;
25- import 'package:pub_dev/service/download_counts/backend.dart' ;
26- import 'package:pub_dev/shared/popularity_storage.dart' ;
27- import 'package:pub_dev/shared/redis_cache.dart' ;
28- import 'package:pub_dev/shared/utils.dart' ;
2922import 'package:retry/retry.dart' ;
3023
24+ import '../../publisher/backend.dart' ;
25+ import '../../service/download_counts/backend.dart' ;
3126import '../../service/topics/models.dart' ;
27+ import '../../shared/popularity_storage.dart' ;
28+ import '../../shared/redis_cache.dart' ;
29+ import '../../shared/utils.dart' ;
3230import '../package/backend.dart' ;
3331import '../package/model_properties.dart' ;
3432import '../package/models.dart' ;
@@ -48,6 +46,7 @@ import 'dart_sdk_mem_index.dart';
4846import 'flutter_sdk_mem_index.dart' ;
4947import 'models.dart' ;
5048import 'result_combiner.dart' ;
49+ import 'search_client.dart' ;
5150import 'search_service.dart' ;
5251import 'text_utils.dart' ;
5352
@@ -549,9 +548,28 @@ SearchForm? canonicalizeSearchForm(SearchForm form) {
549548 }
550549 if (newTags != null ) {
551550 return form.change (query: query.change (tagsPredicate: newTags).toString ());
552- } else {
553- return null ;
554551 }
552+
553+ final newQueryText = form.parsedQuery.text? .split (' ' ).map ((p) {
554+ if (p.startsWith ('#' ) && p.length > 1 ) {
555+ final topic = p.substring (1 );
556+ // Checking the surface format, and skipping the change if the
557+ // text would be an invalid topic.
558+ if (! isValidTopicFormat (topic)) {
559+ return p;
560+ }
561+ // NOTE: We don't know if this topic exists or spelled correctly.
562+ // We should consider restricting the updates to existing
563+ // topics only (TBD).
564+ return 'topic:$topic ' ;
565+ }
566+ return p;
567+ }).join (' ' );
568+ if (newQueryText != form.parsedQuery.text) {
569+ return form.change (query: newQueryText);
570+ }
571+
572+ return null ;
555573}
556574
557575/// Creates the index-related API data structure from the extracted dartdoc data.
0 commit comments