Skip to content

Commit

Permalink
Added test of FTS with prefix on embedded objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Feb 5, 2024
1 parent a013fe0 commit 5417743
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/indexed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ const String lordOfTheFlies = 'Lord of the Flies';
const String wheelOfTime = 'The Wheel of Time';
const String silmarillion = 'The Silmarillion';

@RealmModel()
class _ParentWithFts {
@Indexed(RealmIndexType.fullText)
late String name;
List<_EmbeddedWithFts> embedded = [];
}

@RealmModel(ObjectType.embeddedObject)
class _EmbeddedWithFts {
@Indexed(RealmIndexType.fullText)
late String nameSingular;
@Indexed(RealmIndexType.fullText)
late String namePlural;
}

void main() {
setupTests();

Expand Down Expand Up @@ -240,4 +255,37 @@ void main() {

expect(() => realm.query<ObjectWithFTSIndex>('title TEXT \$0', ["lord"]), throws<RealmException>('Column has no fulltext index'));
});

group('FTS with prefix search on embedded objects', () {
late Realm realm;
setUpAll(() {
final config = Configuration.local([ParentWithFts.schema, EmbeddedWithFts.schema]);
realm = Realm(config);

realm.write(() {
realm.addAll([
ParentWithFts('Object 1', embedded: [
EmbeddedWithFts('salt', 'salt'),
EmbeddedWithFts('pepper', 'pepper'),
]),
ParentWithFts('Object 2', embedded: [
EmbeddedWithFts('basil', 'basil'),
EmbeddedWithFts('oregano', 'oregano'),
])
]);
});
});

for (final searchTerm in [
'sal*',
'Object 2*',
'basil*',
'Object*',
'doesnotexist*',
]) {
test('search term: $searchTerm', () {
expect(realm.query<ParentWithFts>(r"name TEXT $0 OR embedded.nameSingular TEXT $0 OR embedded.namePlural TEXT $0", [searchTerm]).first, isNotNull);

Check failure on line 287 in test/indexed_test.dart

View workflow job for this annotation

GitHub Actions / Test Results Dart linux

test/indexed_test.dart ► FTS with prefix search on embedded objects ► search term: doesnotexist*

Failed test found in: test-results.json Error: Bad state: No element
Raw output
package:realm_dart/src/results.dart 120:7  RealmResults.first
test/indexed_test.dart 287:138             main.<fn>.<fn>

Check failure on line 287 in test/indexed_test.dart

View workflow job for this annotation

GitHub Actions / Test Results Dart windows

test/indexed_test.dart ► FTS with prefix search on embedded objects ► search term: doesnotexist*

Failed test found in: test-results.json Error: Bad state: No element
Raw output
package:realm_dart/src/results.dart 120:7  RealmResults.first
test\indexed_test.dart 287:138             main.<fn>.<fn>
});
}
});
}
96 changes: 96 additions & 0 deletions test/indexed_test.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5417743

Please sign in to comment.