Skip to content

Commit

Permalink
Add reference property in Field class.
Browse files Browse the repository at this point in the history
  • Loading branch information
happy-san committed Apr 1, 2024
1 parent 7ccec3b commit f075ab0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.5.1

* Added `reference` property in `Field` class.

# 0.5.0

* Added support for nested object fields.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/console-simple/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ packages:
path: "../.."
relative: true
source: path
version: "0.5.0"
version: "0.5.1"
web:
dependency: transitive
description:
Expand Down
16 changes: 14 additions & 2 deletions lib/src/models/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
Expand All @@ -77,6 +83,7 @@ class Field {
locale: map['locale'],
sort: map['sort'] ?? false,
enableInfixSearch: map['infix'] ?? false,
reference: map['reference'],
);
}

Expand Down Expand Up @@ -107,6 +114,9 @@ class Field {
if (enableInfixSearch) {
map['infix'] = true;
}
if (reference != null) {
map['reference'] = reference;
}
return map;
}

Expand All @@ -126,7 +136,8 @@ class Field {
shouldIndex.hashCode ^
locale.hashCode ^
sort.hashCode ^
enableInfixSearch.hashCode;
enableInfixSearch.hashCode ^
reference.hashCode;

@override
bool operator ==(Object other) {
Expand All @@ -141,7 +152,8 @@ class Field {
other.shouldIndex == shouldIndex &&
other.locale == locale &&
other.sort == sort &&
other.enableInfixSearch == enableInfixSearch;
other.enableInfixSearch == enableInfixSearch &&
other.reference == reference;
}
}

Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,3 +15,4 @@ dev_dependencies:
mockito: ^5.4.4
lints: ^3.0.0
build_runner: ^2.4.8
analyzer: ^6.4.1
8 changes: 8 additions & 0 deletions test/models/field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {
locale: 'en',
sort: true,
enableInfixSearch: true,
reference: 'RefColl.field',
);
f2 = Field.fromMap({
"name": "country",
Expand All @@ -26,6 +27,7 @@ void main() {
"locale": "en",
"sort": true,
"infix": true,
"reference": "RefColl.field",
});
});

Expand Down Expand Up @@ -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',
Expand All @@ -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));
Expand Down Expand Up @@ -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()', () {
Expand Down

0 comments on commit f075ab0

Please sign in to comment.