From f075ab01c5b7beae194db93747b2b90217398246 Mon Sep 17 00:00:00 2001 From: Harpreet Sangar Date: Mon, 1 Apr 2024 18:22:37 +0530 Subject: [PATCH] Add `reference` property in `Field` class. --- CHANGELOG.md | 4 ++++ README.md | 2 +- example/console-simple/pubspec.lock | 2 +- lib/src/models/field.dart | 16 ++++++++++++++-- pubspec.yaml | 3 ++- test/models/field_test.dart | 8 ++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f6e8b1..7113309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.5.1 + +* Added `reference` property in `Field` class. + # 0.5.0 * Added support for nested object fields. diff --git a/README.md b/README.md index 4b87ab0..43594b5 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Add `typesense` as a [dependency in your pubspec.yaml file](https://flutter.dev/ ```@yaml dependencies: - typesense: ^0.5.0 + typesense: ^0.5.1 ``` ## Usage diff --git a/example/console-simple/pubspec.lock b/example/console-simple/pubspec.lock index 1aab4b7..73d9051 100644 --- a/example/console-simple/pubspec.lock +++ b/example/console-simple/pubspec.lock @@ -127,7 +127,7 @@ packages: path: "../.." relative: true source: path - version: "0.5.0" + version: "0.5.1" web: dependency: transitive description: diff --git a/lib/src/models/field.dart b/lib/src/models/field.dart index 6e8d5ba..da89ae2 100644 --- a/lib/src/models/field.dart +++ b/lib/src/models/field.dart @@ -43,6 +43,11 @@ class Field { /// be enabled on a per-field basis. final bool enableInfixSearch; + /// Connects a document to a field in another collection. + /// + /// Example value: `ReferencedCollectionName.fieldName`. + final String? reference; + Field( this.name, { this.type, @@ -54,6 +59,7 @@ class Field { this.locale, this.sort = false, this.enableInfixSearch = false, + this.reference, }) { if (name.isEmpty) { throw ArgumentError('Ensure Field.name is not empty'); @@ -77,6 +83,7 @@ class Field { locale: map['locale'], sort: map['sort'] ?? false, enableInfixSearch: map['infix'] ?? false, + reference: map['reference'], ); } @@ -107,6 +114,9 @@ class Field { if (enableInfixSearch) { map['infix'] = true; } + if (reference != null) { + map['reference'] = reference; + } return map; } @@ -126,7 +136,8 @@ class Field { shouldIndex.hashCode ^ locale.hashCode ^ sort.hashCode ^ - enableInfixSearch.hashCode; + enableInfixSearch.hashCode ^ + reference.hashCode; @override bool operator ==(Object other) { @@ -141,7 +152,8 @@ class Field { other.shouldIndex == shouldIndex && other.locale == locale && other.sort == sort && - other.enableInfixSearch == enableInfixSearch; + other.enableInfixSearch == enableInfixSearch && + other.reference == reference; } } diff --git a/pubspec.yaml b/pubspec.yaml index 53c2b33..dff01bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: typesense description: Dart client library for accessing the HTTP API of Typesense search engine. -version: 0.5.0 +version: 0.5.1 repository: https://github.com/typesense/typesense-dart environment: @@ -15,3 +15,4 @@ dev_dependencies: mockito: ^5.4.4 lints: ^3.0.0 build_runner: ^2.4.8 + analyzer: ^6.4.1 diff --git a/test/models/field_test.dart b/test/models/field_test.dart index ffe0430..35d96dc 100644 --- a/test/models/field_test.dart +++ b/test/models/field_test.dart @@ -16,6 +16,7 @@ void main() { locale: 'en', sort: true, enableInfixSearch: true, + reference: 'RefColl.field', ); f2 = Field.fromMap({ "name": "country", @@ -26,6 +27,7 @@ void main() { "locale": "en", "sort": true, "infix": true, + "reference": "RefColl.field", }); }); @@ -65,6 +67,10 @@ void main() { expect(f1.enableInfixSearch, isTrue); expect(f2.enableInfixSearch, isTrue); }); + test('has a reference field', () { + expect(f1.reference, 'RefColl.field'); + expect(f2.reference, 'RefColl.field'); + }); test('has a toMap method', () { final map = { 'name': 'country', @@ -73,6 +79,7 @@ void main() { 'locale': 'en', 'sort': true, 'infix': true, + 'reference': 'RefColl.field', }; expect(f1.toMap(), equals(map)); expect(f2.toMap(), equals(map)); @@ -265,6 +272,7 @@ void main() { expect(field.locale, isNull); expect(field.sort, isFalse); expect(field.enableInfixSearch, isFalse); + expect(field.reference, isNull); }); }); group('Field toMap()', () {