@@ -22,6 +22,11 @@ import 'package:pub_dev/shared/utils.dart';
2222final _logger = Logger ('search_index' );
2323
2424final _argParser = ArgParser ()
25+ ..addFlag (
26+ 'remove-text-content' ,
27+ defaultsTo: false ,
28+ help: 'When set, the text content of the index will be removed.' ,
29+ )
2530 ..addOption (
2631 'snapshot' ,
2732 help:
@@ -34,6 +39,7 @@ Future<void> main(List<String> args, var message) async {
3439
3540 final argv = _argParser.parse (args);
3641 final snapshot = argv['snapshot' ] as String ? ;
42+ final removeTextContent = (argv['remove-text-content' ] as bool ? ) ?? false ;
3743
3844 final ServicesWrapperFn servicesWrapperFn;
3945 if (envConfig.isRunningInAppengine) {
@@ -46,9 +52,10 @@ Future<void> main(List<String> args, var message) async {
4652 await fork (() async {
4753 await servicesWrapperFn (() async {
4854 if (snapshot == null ) {
49- await indexUpdater.init ();
55+ await indexUpdater.init (removeTextContent : removeTextContent );
5056 } else {
51- updatePackageIndex (await loadInMemoryPackageIndexFromFile (snapshot));
57+ updatePackageIndex (await loadInMemoryPackageIndexFromFile (snapshot,
58+ removeTextContent: removeTextContent));
5259 }
5360
5461 await runIsolateFunctions (
@@ -75,12 +82,30 @@ Future<void> main(List<String> args, var message) async {
7582 timer.cancel ();
7683}
7784
85+ /// Starts a new search isolate with optional overrides.
86+ Future <IsolateRunner > startSearchIsolate ({
87+ Logger ? logger,
88+ bool removeTextContent = false ,
89+ String ? snapshot,
90+ }) async {
91+ return await startQueryIsolate (
92+ logger: logger ?? _logger,
93+ kind: removeTextContent ? 'reduced' : 'primary' ,
94+ spawnUri: Uri .parse ('package:pub_dev/service/entrypoint/search_index.dart' ),
95+ spawnArgs: [
96+ if (snapshot != null ) ...['--snapshot' , snapshot],
97+ if (removeTextContent) '--remove-text-content' ,
98+ ],
99+ );
100+ }
101+
78102/// Implementation of [SearchIndex] that uses [RequestMessage] s to send requests
79103/// across isolate boundaries. The instance should be registered inside the
80104/// `frontend` isolate, and it calls the `index` isolate as a delegate.
81105class IsolateSearchIndex implements SearchIndex {
82- final IsolateRunner _runner;
83- IsolateSearchIndex (this ._runner);
106+ final IsolateRunner _primary;
107+ final IsolateRunner _reduced;
108+ IsolateSearchIndex (this ._primary, this ._reduced);
84109 var _isReady = false ;
85110
86111 @override
@@ -96,7 +121,7 @@ class IsolateSearchIndex implements SearchIndex {
96121 @override
97122 FutureOr <IndexInfo > indexInfo () async {
98123 try {
99- final info = await _runner .sendRequest (
124+ final info = await _primary .sendRequest (
100125 'info' ,
101126 timeout: Duration (seconds: 5 ),
102127 );
@@ -114,7 +139,8 @@ class IsolateSearchIndex implements SearchIndex {
114139 @override
115140 FutureOr <PackageSearchResult > search (ServiceSearchQuery query) async {
116141 try {
117- final rs = await _runner.sendRequest (
142+ final runner = query.parsedQuery.hasFreeText ? _primary : _reduced;
143+ final rs = await runner.sendRequest (
118144 Uri (queryParameters: query.toUriQueryParameters ()).toString (),
119145 timeout: Duration (minutes: 1 ),
120146 );
0 commit comments