diff --git a/bin/main.dart b/bin/main.dart index 9a42576..52532b5 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -8,7 +8,8 @@ import 'package:alfred_workflow/alfred_workflow.dart' AlfredItems, AlfredUpdater, AlfredWorkflow; -import 'package:algolia/algolia.dart' show AlgoliaQuerySnapshot; +import 'package:algoliasearch/src/model/hit.dart'; +import 'package:algoliasearch/src/model/search_response.dart'; import 'package:args/args.dart' show ArgParser, ArgResults; import 'package:cli_script/cli_script.dart'; diff --git a/bin/main_helpers.dart b/bin/main_helpers.dart index a408e00..b259ba4 100644 --- a/bin/main_helpers.dart +++ b/bin/main_helpers.dart @@ -29,53 +29,56 @@ void _showPlaceholder() { } Future _performSearch(String query) async { - final AlgoliaQuerySnapshot snapshot = await AlgoliaSearch.query(query); + try { + final SearchResponse searchResponse = await AlgoliaSearch.query(query); - if (snapshot.nbHits > 0) { - final AlfredItems items = AlfredItems( - snapshot.hits - .map( - (snapshot) => SearchResult.fromJson(snapshot.data), - ) - .map( - (result) => AlfredItem( - uid: result.objectID, - title: '${result.name} ${result.type}', - subtitle: result.enclosedBy != null - ? 'from ${result.enclosedBy!["name"]}' - : '', - arg: result.href, - text: AlfredItemText( - copy: result.href, - largeType: result.qualifiedName, + if (searchResponse.nbHits > 0) { + final AlfredItems items = AlfredItems( + searchResponse.hits + .map((Hit hit) => SearchResult.fromJson( + {...hit, 'objectID': hit.objectID})) + .map( + (SearchResult result) => AlfredItem( + uid: result.objectID, + title: '${result.name} ${result.type}', + subtitle: result.enclosedBy != null + ? 'from ${result.enclosedBy!["name"]}' + : '', + arg: result.href, + text: AlfredItemText( + copy: result.href, + largeType: result.qualifiedName, + ), + quickLookUrl: result.href, + icon: AlfredItemIcon(path: 'icon.png'), + valid: true, ), - quickLookUrl: result.href, - icon: AlfredItemIcon(path: 'icon.png'), - valid: true, - ), - ) - .toList(), - ); - _workflow.addItems(items.items); - } else { - final Uri url = Uri.https( - 'www.google.com', - '/search', - {'q': 'flutter $query'}, - ); + ) + .toList(), + ); + _workflow.addItems(items.items); + } else { + final Uri url = Uri.https( + 'www.google.com', + '/search', + {'q': 'flutter $query'}, + ); - _workflow.addItem( - AlfredItem( - title: 'No matching answers found', - subtitle: 'Shall I try and search Google?', - arg: url.toString(), - text: AlfredItemText( - copy: url.toString(), + _workflow.addItem( + AlfredItem( + title: 'No matching answers found', + subtitle: 'Shall I try and search Google?', + arg: url.toString(), + text: AlfredItemText( + copy: url.toString(), + ), + quickLookUrl: url.toString(), + icon: AlfredItemIcon(path: 'google.png'), + valid: true, ), - quickLookUrl: url.toString(), - icon: AlfredItemIcon(path: 'google.png'), - valid: true, - ), - ); + ); + } + } finally { + AlgoliaSearch.dispose(); } } diff --git a/bin/src/services/algolia_search.dart b/bin/src/services/algolia_search.dart index 48b8ad4..d3e1669 100644 --- a/bin/src/services/algolia_search.dart +++ b/bin/src/services/algolia_search.dart @@ -1,5 +1,4 @@ -import 'package:algolia/algolia.dart' - show Algolia, AlgoliaQuery, AlgoliaQuerySnapshot; +import 'package:algoliasearch/algoliasearch_lite.dart'; import '../env/env.dart'; import '../models/search_result.dart'; @@ -7,19 +6,22 @@ import '../models/search_result.dart'; class AlgoliaSearch { AlgoliaSearch._(); - static final Algolia _algolia = Algolia.init( - applicationId: Env.algoliaApplicationId, + static final SearchClient _client = SearchClient( + appId: Env.algoliaApplicationId, apiKey: Env.algoliaSearchOnlyApiKey, ); - static Future query(String queryString) async { - final AlgoliaQuery query = _algolia.instance - .index(Env.algoliaSearchIndex) - .query(queryString) - .setAttributesToRetrieve(SearchResult.attributesToRetrieve) - .setPage(0) - .setHitsPerPage(20); + static Future query(String queryString) => + _client.searchIndex( + request: SearchForHits( + indexName: Env.algoliaSearchIndex, + query: queryString, + attributesToRetrieve: SearchResult.attributesToRetrieve, + distinct: 1, + page: 0, + hitsPerPage: 20, + ), + ); - return await query.getObjects(); - } + static dispose() => _client.dispose(); } diff --git a/pubspec.lock b/pubspec.lock index 01a9617..b32b5ea 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,18 +13,42 @@ packages: dependency: "direct main" description: name: alfred_workflow - sha256: f3d8da44e2783d4495755c72a9769118bb10f45fc3a596ab9e2bae1badd58da9 + sha256: af5fdb2d4111cacc99023a44152db24e8c6f443c59a0b6ac034fc6c29c09f0ad url: "https://pub.dev" source: hosted - version: "0.5.0" - algolia: + version: "0.5.1" + algolia_client_core: + dependency: transitive + description: + name: algolia_client_core + sha256: e233464ac15f1b53001998e573b66301ae0b88dd465ec91c9dd52a3be666eebc + url: "https://pub.dev" + source: hosted + version: "1.2.0" + algolia_client_insights: + dependency: transitive + description: + name: algolia_client_insights + sha256: "5d2407b4a086027f2ce3542bb400c6771d3461a576af1e129321c9ec5fe6f183" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + algolia_client_search: + dependency: transitive + description: + name: algolia_client_search + sha256: "72e7e2754be385edcb05cbe4f168eecf573278ed083032a3d338a7880deb62d4" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + algoliasearch: dependency: "direct main" description: - name: algolia - sha256: "0ba325344f85ac8f8351d158f0be0643e169ac0c91a43a496f8b1f3b54390066" + name: algoliasearch + sha256: "5162f27e982db30146040f568fbcd032d5ef88cad010d125a9f0fdfcc306e6b0" url: "https://pub.dev" source: hosted - version: "1.1.2" + version: "1.2.0" analyzer: dependency: transitive description: @@ -53,10 +77,10 @@ packages: dependency: transitive description: name: autoequal - sha256: effd2d17d7ff54e8482122bd43742b731c6d9a91d3b80db8ee1cb03df8b63ec1 + sha256: "321091dcf5bf9492b67d2e7f98cfb5a789dfd63e28d041bd4fe34e319e424cfa" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.7.1" boolean_selector: dependency: transitive description: @@ -93,18 +117,18 @@ packages: dependency: transitive description: name: build_resolvers - sha256: "64e12b0521812d1684b1917bc80945625391cb9bdd4312536b1d69dcb6133ed8" + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" url: "https://pub.dev" source: hosted - version: "2.4.1" + version: "2.4.2" build_runner: dependency: "direct dev" description: name: build_runner - sha256: "10c6bcdbf9d049a0b666702cf1cee4ddfdc38f02a19d35ae392863b47519848b" + sha256: "67d591d602906ef9201caf93452495ad1812bea2074f04e25dbd7c133785821b" url: "https://pub.dev" source: hosted - version: "2.4.6" + version: "2.4.7" build_runner_core: dependency: transitive description: @@ -125,10 +149,10 @@ packages: dependency: transitive description: name: built_value - sha256: "723b4021e903217dfc445ec4cf5b42e27975aece1fc4ebbc1ca6329c2d9fb54e" + sha256: c9aabae0718ec394e5bc3c7272e6bb0dc0b32201a08fe185ec1d8401d3e39309 url: "https://pub.dev" source: hosted - version: "8.7.0" + version: "8.8.1" charcode: dependency: transitive description: @@ -165,10 +189,10 @@ packages: dependency: transitive description: name: code_builder - sha256: b2151ce26a06171005b379ecff6e08d34c470180ffe16b8e14b6d52be292b55f + sha256: feee43a5c05e7b3199bb375a86430b8ada1b04104f2923d0e03cc01ca87b6d84 url: "https://pub.dev" source: hosted - version: "4.8.0" + version: "4.9.0" collection: dependency: transitive description: @@ -209,6 +233,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.4" + dio: + dependency: transitive + description: + name: dio + sha256: "797e1e341c3dd2f69f2dad42564a6feff3bfb87187d05abb93b9609e6f1645c3" + url: "https://pub.dev" + source: hosted + version: "5.4.0" envied: dependency: "direct main" description: @@ -274,13 +306,13 @@ packages: source: hosted version: "2.3.1" http: - dependency: "direct overridden" + dependency: transitive description: name: http - sha256: "38dce67ce909c338754840e2a1479c2c11347a2fc7ec3d5b166a5118a8a201db" + sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139 url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.2" http_multi_server: dependency: transitive description: @@ -349,10 +381,10 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" meta: dependency: transitive description: @@ -381,18 +413,18 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" petitparser: dependency: transitive description: name: petitparser - sha256: eeb2d1428ee7f4170e2bd498827296a18d4e7fc462b71727d111c0ac7707cfa6 + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 url: "https://pub.dev" source: hosted - version: "6.0.1" + version: "6.0.2" plist_parser: dependency: transitive description: @@ -453,10 +485,10 @@ packages: dependency: transitive description: name: source_gen - sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 + sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832" url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.5.0" source_helper: dependency: transitive description: @@ -541,10 +573,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" timing: dependency: transitive description: @@ -569,22 +601,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" - universal_io: - dependency: transitive - description: - name: universal_io - sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad" - url: "https://pub.dev" - source: hosted - version: "2.2.2" uuid: - dependency: "direct overridden" + dependency: transitive description: name: uuid - sha256: df5a4d8f22ee4ccd77f8839ac7cb274ebc11ef9adcce8b92be14b797fe889921 + sha256: bb55f38968b9427ce5dcdb8aaaa41049282195e0cfa4cf48593572fa3d1f36bc url: "https://pub.dev" source: hosted - version: "4.2.1" + version: "4.3.1" watcher: dependency: transitive description: @@ -613,10 +637,10 @@ packages: dependency: transitive description: name: xml - sha256: af5e77e9b83f2f4adc5d3f0a4ece1c7f45a2467b695c2540381bac793e34e556 + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 url: "https://pub.dev" source: hosted - version: "6.4.2" + version: "6.5.0" yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index df7b996..4116515 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,15 +4,15 @@ description: Search the Flutter documentation using Alfred # Prevent accidental publishing to pub.dev. publish_to: 'none' -version: 2.1.9 +version: 2.1.10 environment: sdk: '>=3.2.0 <4.0.0' dependencies: - algolia: ^1.1.2 + algoliasearch: ^1.2.0 args: ^2.4.2 - alfred_workflow: ^0.5.0 + alfred_workflow: ^0.5.1 cli_script: ^1.0.0 envied: ^0.5.2 json_annotation: ^4.8.1 @@ -22,7 +22,3 @@ dev_dependencies: envied_generator: ^0.5.2 json_serializable: ^6.7.1 lints: ^3.0.0 - -dependency_overrides: - http: ^1.1.1 - uuid: 4.2.1