@@ -32,8 +32,6 @@ const _defaultApiPageDirWeights = {
3232
3333/// In-memory index for SDK library search queries.
3434class SdkMemIndex {
35- final String _sdk;
36- final Uri _baseUri;
3735 final _libraries = < String , _Library > {};
3836 final Map <String , double > _apiPageDirWeights;
3937
@@ -43,10 +41,8 @@ class SdkMemIndex {
4341 required DartdocIndex index,
4442 Set <String >? allowedLibraries,
4543 Map <String , double >? apiPageDirWeights,
46- }) : _sdk = sdk,
47- _baseUri = baseUri,
48- _apiPageDirWeights = apiPageDirWeights ?? _defaultApiPageDirWeights {
49- _addDartdocIndex (index, allowedLibraries);
44+ }) : _apiPageDirWeights = apiPageDirWeights ?? _defaultApiPageDirWeights {
45+ _addDartdocIndex (sdk, baseUri, index, allowedLibraries);
5046 }
5147
5248 static SdkMemIndex dart ({required DartdocIndex index}) {
@@ -72,11 +68,13 @@ class SdkMemIndex {
7268 Uri .parse ('https://api.flutter.dev/flutter/index.json' );
7369
7470 void _addDartdocIndex (
71+ String sdk,
72+ Uri baseUri,
7573 DartdocIndex index,
7674 Set <String >? allowedLibraries,
7775 ) {
7876 final textsPerLibrary = < String , Map <String , String >> {};
79- final baseUrls = < String , String > {};
77+ final baseUris = < String , Uri > {};
8078 final descriptions = < String , String > {};
8179
8280 for (final f in index.entries) {
@@ -89,7 +87,7 @@ class SdkMemIndex {
8987 continue ;
9088 }
9189 if (f.isLibrary) {
92- baseUrls [library] = _baseUri .resolve (f.href! ). toString ( );
90+ baseUris [library] = baseUri .resolve (f.href! );
9391
9492 final desc = f.desc? .replaceAll (RegExp (r'\s+' ), ' ' ).trim ();
9593 if (desc != null && desc.isNotEmpty) {
@@ -105,8 +103,9 @@ class SdkMemIndex {
105103 }
106104 for (final e in textsPerLibrary.entries) {
107105 _libraries[e.key] = _Library (
106+ sdk: sdk,
108107 name: e.key,
109- baseUrl : baseUrls [e.key],
108+ baseUri : baseUris [e.key] ?? baseUri ,
110109 description: descriptions[e.key],
111110 tokenIndex: TokenIndex .fromMap (e.value),
112111 );
@@ -156,16 +155,16 @@ class SdkMemIndex {
156155 .take (limit)
157156 .where ((h) => h.score >= minScore)
158157 .map ((hit) => SdkLibraryHit (
159- sdk: _sdk ,
158+ sdk: hit.library.sdk ,
160159 library: hit.library.name,
161160 description: hit.library.description,
162- url: hit.library.baseUrl ?? _baseUri. toString () ,
161+ url: hit.library.url ,
163162 score: hit.score,
164163 apiPages: hit.top.entries
165164 .map (
166165 (e) => ApiPageRef (
167166 path: e.key,
168- url: _baseUri .resolve (e.key).toString (),
167+ url: hit.library.baseUri .resolve (e.key).toString (),
169168 ),
170169 )
171170 .toList (),
@@ -188,18 +187,21 @@ class _Hit {
188187}
189188
190189class _Library {
190+ final String sdk;
191191 final String name;
192- final String ? baseUrl ;
192+ final Uri baseUri ;
193193 final String ? description;
194194 final TokenIndex <String > tokenIndex;
195195
196196 _Library ({
197+ required this .sdk,
197198 required this .name,
198- required this .baseUrl ,
199+ required this .baseUri ,
199200 required this .description,
200201 required this .tokenIndex,
201202 });
202203
204+ late final url = baseUri.toString ();
203205 late final weight = _libraryWeights[name] ?? 1.0 ;
204206 late final lastNamePart = name.split (':' ).last;
205207}
0 commit comments