From d56eeaa0bb9f495c2e77097c4606c9bc90d605a9 Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Mon, 2 Feb 2026 20:38:49 +0200 Subject: [PATCH 1/2] feat(example): add curations console example --- example/console-simple/bin/curations.dart | 165 ++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 example/console-simple/bin/curations.dart diff --git a/example/console-simple/bin/curations.dart b/example/console-simple/bin/curations.dart new file mode 100644 index 0000000..bbdc8d9 --- /dev/null +++ b/example/console-simple/bin/curations.dart @@ -0,0 +1,165 @@ +import 'package:typesense/typesense.dart'; +import 'package:logging/logging.dart'; + +import 'collections.dart' as collections; +import 'documents.dart' as documents; +import 'util.dart'; + +final log = Logger('Curations'); + +Future runExample(Client client) async { + logInfoln(log, '--Curations example--'); + await init(client); + await create(client); + await retrieveAll(client); + await retrieveSet(client); + await retrieveItem(client); + await deleteItem(client); + await deleteSet(client); + await collections.delete(client); +} + +final _documents = [ + { + 'id': '124', + 'company_name': 'Stark Industries', + 'num_employees': 5215, + 'country': 'USA' + }, + { + 'id': '125', + 'company_name': 'Acme Corp', + 'num_employees': 1002, + 'country': 'France' + }, + { + 'id': '127', + 'company_name': 'Stark Corp', + 'num_employees': 1031, + 'country': 'USA' + }, + { + 'id': '126', + 'company_name': 'Doofenshmirtz Inc', + 'num_employees': 2, + 'country': 'Tri-State Area' + } +]; + +Future init(Client client) async { + await documents.init(client); + await documents.importDocs(client, 'companies', _documents); +} + +Future create(Client client) async { + try { + logInfoln(log, 'Creating curation set "curate_companies".'); + final curationSet = CurationSetUpsertSchema( + items: [ + CurationObjectSchema( + id: 'promote-doofenshmirtz', + rule: CurationRuleSchema(query: 'doofen', match: 'exact'), + includes: [ + CurationIncludeSchema(id: '126', position: 1), + ], + ), + ], + ); + + final response = + await client.curationSet('curate_companies').upsert(curationSet); + log.fine({ + 'name': response.name, + 'items': response.items.map((item) => item.toJson()).toList(), + }); + await writePropagationDelay(); + + logInfoln(log, 'Adding "curate_companies" to "companies" collection.'); + final updateResponse = await client.collection('companies').update( + UpdateSchema( + {}, + curationSets: {'curate_companies'}, + ), + ); + log.fine(updateResponse); + await writePropagationDelay(); + } on RequestException catch (e, stackTrace) { + log.severe(e.message, e, stackTrace); + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } +} + +Future retrieveAll(Client client) async { + try { + logInfoln(log, 'Retrieving all curation sets.'); + final response = await client.curationSets.retrieve(); + for (final set in response) { + log.fine({ + 'name': set.name, + 'items': set.items.map((item) => item.toJson()).toList(), + }); + } + } on RequestException catch (e, stackTrace) { + log.severe(e.message, e, stackTrace); + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } +} + +Future retrieveSet(Client client) async { + try { + logInfoln(log, 'Retrieving curation set "curate_companies".'); + final response = await client.curationSet('curate_companies').retrieve(); + log.fine({ + 'name': response.name, + 'items': response.items.map((item) => item.toJson()).toList(), + }); + } on RequestException catch (e, stackTrace) { + log.severe(e.message, e, stackTrace); + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } +} + +Future retrieveItem(Client client) async { + try { + logInfoln(log, 'Retrieving curation item "promote-doofenshmirtz".'); + final response = await client + .curationSet('curate_companies') + .getItem('promote-doofenshmirtz'); + log.fine(response.toJson()); + } on RequestException catch (e, stackTrace) { + log.severe(e.message, e, stackTrace); + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } +} + +Future deleteItem(Client client) async { + try { + logInfoln(log, 'Deleting curation item "promote-doofenshmirtz".'); + final response = await client + .curationSet('curate_companies') + .deleteItem('promote-doofenshmirtz'); + log.fine({'id': response.id}); + await writePropagationDelay(); + } on RequestException catch (e, stackTrace) { + log.severe(e.message, e, stackTrace); + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } +} + +Future deleteSet(Client client) async { + try { + logInfoln(log, 'Deleting curation set "curate_companies".'); + final response = await client.curationSet('curate_companies').delete(); + log.fine({'name': response.name}); + await writePropagationDelay(); + } on RequestException catch (e, stackTrace) { + log.severe(e.message, e, stackTrace); + } catch (e, stackTrace) { + log.severe(e, stackTrace); + } +} From 32c45dc33a57223e520ff2fde19a95a458256f9b Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Mon, 2 Feb 2026 20:39:27 +0200 Subject: [PATCH 2/2] refactor(example): replace overrides example with curations - switch console entrypoint to run curations workflow - remove deprecated overrides example implementation --- example/console-simple/bin/main.dart | 4 +- example/console-simple/bin/overrides.dart | 114 ---------------------- 2 files changed, 2 insertions(+), 116 deletions(-) delete mode 100644 example/console-simple/bin/overrides.dart diff --git a/example/console-simple/bin/main.dart b/example/console-simple/bin/main.dart index d0600f9..a1f503f 100644 --- a/example/console-simple/bin/main.dart +++ b/example/console-simple/bin/main.dart @@ -7,7 +7,7 @@ import 'collections.dart' as collections; import 'documents.dart' as documents; import 'search.dart' as search; import 'keys.dart' as keys; -import 'overrides.dart' as overrides; +import 'curations.dart' as curations; import 'synonyms.dart' as synonyms; import 'aliases.dart' as aliases; import 'presets.dart' as presets; @@ -55,7 +55,7 @@ void main() async { Client(config.copyWith(connectionTimeout: const Duration(seconds: 120)))); await search.runExample(client); await keys.runExample(client); - await overrides.runExample(client); + await curations.runExample(client); await synonyms.runExample(client); await aliases.runExample(client); await presets.runExample(client); diff --git a/example/console-simple/bin/overrides.dart b/example/console-simple/bin/overrides.dart deleted file mode 100644 index 7f814f5..0000000 --- a/example/console-simple/bin/overrides.dart +++ /dev/null @@ -1,114 +0,0 @@ -import 'package:typesense/typesense.dart'; -import 'package:logging/logging.dart'; - -import 'util.dart'; -import 'collections.dart' as collections; -import 'documents.dart' as documents; - -final log = Logger('Overrides'); - -Future runExample(Client client) async { - logInfoln(log, '--Overrides example--'); - await init(client); - await create(client); - await retrieveAll(client); - await retrieve(client); - await delete(client); - await collections.delete(client); -} - -final _documents = [ - { - 'id': '124', - 'company_name': 'Stark Industries', - 'num_employees': 5215, - 'country': 'USA' - }, - { - 'id': '125', - 'company_name': 'Acme Corp', - 'num_employees': 1002, - 'country': 'France' - }, - { - 'id': '127', - 'company_name': 'Stark Corp', - 'num_employees': 1031, - 'country': 'USA' - }, - { - 'id': '126', - 'company_name': 'Doofenshmirtz Inc', - 'num_employees': 2, - 'country': 'Tri-State Area' - } -]; - -Future init(Client client) async { - await documents.init(client); - await documents.importDocs(client, 'companies', _documents); -} - -Future create(Client client) async { - try { - logInfoln(log, 'Creating override.'); - log.fine( - await client.collection('companies').overrides.upsert( - 'promote-doofenshmirtz', - { - 'rule': {'query': 'doofen', 'match': 'exact'}, - 'includes': [ - {'id': '126', 'position': 1} - ] - }, - ), - ); - - await writePropagationDelay(); - } on RequestException catch (e, stackTrace) { - log.severe(e.message, e, stackTrace); - } catch (e, stackTrace) { - log.severe(e, stackTrace); - } -} - -Future retrieveAll(Client client) async { - try { - logInfoln(log, 'Retrieving all overrides.'); - log.fine(await client.collection('companies').overrides.retrieve()); - } on RequestException catch (e, stackTrace) { - log.severe(e.message, e, stackTrace); - } catch (e, stackTrace) { - log.severe(e, stackTrace); - } -} - -Future retrieve(Client client) async { - try { - logInfoln(log, 'Retrieving override "promote-doofenshmirtz".'); - log.fine(await client - .collection('companies') - .override('promote-doofenshmirtz') - .retrieve()); - } on RequestException catch (e, stackTrace) { - log.severe(e.message, e, stackTrace); - } catch (e, stackTrace) { - log.severe(e, stackTrace); - } -} - -Future delete(Client client) async { - try { - logInfoln(log, 'Deleting override "promote-doofenshmirtz".'); - log.fine(await client - .collection('companies') - .override('promote-doofenshmirtz') - .delete()); - - await writePropagationDelay(); - } on RequestException catch (e, stackTrace) { - log.severe(e.message, e, stackTrace); - } catch (e, stackTrace) { - log.severe(e, stackTrace); - } -}