|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
| 5 | +import 'dart:async'; |
| 6 | + |
5 | 7 | import 'package:_pub_shared/search/tags.dart'; |
6 | 8 | import 'package:collection/collection.dart'; |
7 | 9 |
|
8 | | -import 'mem_index.dart'; |
9 | 10 | import 'sdk_mem_index.dart'; |
10 | 11 | import 'search_service.dart'; |
11 | 12 |
|
12 | 13 | /// Combines the results from the primary package index and the optional Dart |
13 | 14 | /// SDK index. |
14 | | -class SearchResultCombiner { |
15 | | - final InMemoryPackageIndex primaryIndex; |
16 | | - final SdkMemIndex? sdkMemIndex; |
| 15 | +class SearchResultCombiner implements SearchIndex { |
| 16 | + final SearchIndex primaryIndex; |
| 17 | + final SdkIndex? sdkIndex; |
17 | 18 |
|
18 | 19 | SearchResultCombiner({ |
19 | 20 | required this.primaryIndex, |
20 | | - required this.sdkMemIndex, |
| 21 | + required this.sdkIndex, |
21 | 22 | }); |
22 | 23 |
|
23 | | - PackageSearchResult search(ServiceSearchQuery query) { |
24 | | - final primaryResult = primaryIndex.search(query); |
25 | | - if (!query.includeSdkResults) { |
26 | | - return primaryResult; |
| 24 | + @override |
| 25 | + FutureOr<IndexInfo> indexInfo() async { |
| 26 | + return await primaryIndex.indexInfo(); |
| 27 | + } |
| 28 | + |
| 29 | + @override |
| 30 | + FutureOr<bool> isReady() async { |
| 31 | + return await primaryIndex.isReady(); |
| 32 | + } |
| 33 | + |
| 34 | + @override |
| 35 | + Future<PackageSearchResult> search(ServiceSearchQuery query) async { |
| 36 | + if (sdkIndex == null || !query.includeSdkResults) { |
| 37 | + return await primaryIndex.search(query); |
27 | 38 | } |
28 | 39 |
|
29 | 40 | final queryFlutterSdk = query.tagsPredicate.hasNoTagPrefix('sdk:') || |
30 | 41 | query.tagsPredicate.hasTag(SdkTag.sdkFlutter); |
31 | | - final sdkLibraryHits = sdkMemIndex |
32 | | - ?.search(query.query!, limit: 2, skipFlutter: !queryFlutterSdk) |
33 | | - .toList() ?? |
34 | | - <SdkLibraryHit>[]; |
| 42 | + final results = await Future.wait([ |
| 43 | + Future(() => primaryIndex.search(query)), |
| 44 | + Future(() => sdkIndex! |
| 45 | + .search(query.query!, limit: 2, skipFlutter: !queryFlutterSdk)), |
| 46 | + ]); |
| 47 | + final primaryResult = results[0] as PackageSearchResult; |
| 48 | + final sdkLibraryHits = results[1] as List<SdkLibraryHit>; |
| 49 | + |
35 | 50 | if (sdkLibraryHits.isNotEmpty) { |
36 | 51 | // Do not display low SDK scores if the package hits are more relevant on the page. |
37 | 52 | // |
|
0 commit comments