Skip to content

Commit f075ab0

Browse files
committed
Add reference property in Field class.
1 parent 7ccec3b commit f075ab0

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.5.1
2+
3+
* Added `reference` property in `Field` class.
4+
15
# 0.5.0
26

37
* Added support for nested object fields.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Add `typesense` as a [dependency in your pubspec.yaml file](https://flutter.dev/
1212

1313
```@yaml
1414
dependencies:
15-
typesense: ^0.5.0
15+
typesense: ^0.5.1
1616
```
1717

1818
## Usage

example/console-simple/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ packages:
127127
path: "../.."
128128
relative: true
129129
source: path
130-
version: "0.5.0"
130+
version: "0.5.1"
131131
web:
132132
dependency: transitive
133133
description:

lib/src/models/field.dart

+14-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class Field {
4343
/// be enabled on a per-field basis.
4444
final bool enableInfixSearch;
4545

46+
/// Connects a document to a field in another collection.
47+
///
48+
/// Example value: `ReferencedCollectionName.fieldName`.
49+
final String? reference;
50+
4651
Field(
4752
this.name, {
4853
this.type,
@@ -54,6 +59,7 @@ class Field {
5459
this.locale,
5560
this.sort = false,
5661
this.enableInfixSearch = false,
62+
this.reference,
5763
}) {
5864
if (name.isEmpty) {
5965
throw ArgumentError('Ensure Field.name is not empty');
@@ -77,6 +83,7 @@ class Field {
7783
locale: map['locale'],
7884
sort: map['sort'] ?? false,
7985
enableInfixSearch: map['infix'] ?? false,
86+
reference: map['reference'],
8087
);
8188
}
8289

@@ -107,6 +114,9 @@ class Field {
107114
if (enableInfixSearch) {
108115
map['infix'] = true;
109116
}
117+
if (reference != null) {
118+
map['reference'] = reference;
119+
}
110120
return map;
111121
}
112122

@@ -126,7 +136,8 @@ class Field {
126136
shouldIndex.hashCode ^
127137
locale.hashCode ^
128138
sort.hashCode ^
129-
enableInfixSearch.hashCode;
139+
enableInfixSearch.hashCode ^
140+
reference.hashCode;
130141

131142
@override
132143
bool operator ==(Object other) {
@@ -141,7 +152,8 @@ class Field {
141152
other.shouldIndex == shouldIndex &&
142153
other.locale == locale &&
143154
other.sort == sort &&
144-
other.enableInfixSearch == enableInfixSearch;
155+
other.enableInfixSearch == enableInfixSearch &&
156+
other.reference == reference;
145157
}
146158
}
147159

pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: typesense
22
description: Dart client library for accessing the HTTP API of Typesense search engine.
3-
version: 0.5.0
3+
version: 0.5.1
44
repository: https://github.com/typesense/typesense-dart
55

66
environment:
@@ -15,3 +15,4 @@ dev_dependencies:
1515
mockito: ^5.4.4
1616
lints: ^3.0.0
1717
build_runner: ^2.4.8
18+
analyzer: ^6.4.1

test/models/field_test.dart

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void main() {
1616
locale: 'en',
1717
sort: true,
1818
enableInfixSearch: true,
19+
reference: 'RefColl.field',
1920
);
2021
f2 = Field.fromMap({
2122
"name": "country",
@@ -26,6 +27,7 @@ void main() {
2627
"locale": "en",
2728
"sort": true,
2829
"infix": true,
30+
"reference": "RefColl.field",
2931
});
3032
});
3133

@@ -65,6 +67,10 @@ void main() {
6567
expect(f1.enableInfixSearch, isTrue);
6668
expect(f2.enableInfixSearch, isTrue);
6769
});
70+
test('has a reference field', () {
71+
expect(f1.reference, 'RefColl.field');
72+
expect(f2.reference, 'RefColl.field');
73+
});
6874
test('has a toMap method', () {
6975
final map = {
7076
'name': 'country',
@@ -73,6 +79,7 @@ void main() {
7379
'locale': 'en',
7480
'sort': true,
7581
'infix': true,
82+
'reference': 'RefColl.field',
7683
};
7784
expect(f1.toMap(), equals(map));
7885
expect(f2.toMap(), equals(map));
@@ -265,6 +272,7 @@ void main() {
265272
expect(field.locale, isNull);
266273
expect(field.sort, isFalse);
267274
expect(field.enableInfixSearch, isFalse);
275+
expect(field.reference, isNull);
268276
});
269277
});
270278
group('Field toMap()', () {

0 commit comments

Comments
 (0)