Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reference property in Field class. #142

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading