objectbox-dart
objectbox-dart copied to clipboard
Filter DB Entries based on list content
Describe the solution you'd like
I am building a dictionary application and there I have a class Entry that has a List<String> of meanings.
If a user now searches query in the dictionary, I want to get every word that contains the query as a substring.
Example
/* Imagine those two entries in a objectbox DB*/
Entry dictEntry1 = Entry()
dictEntry1.meanings = ["test"];
Entry dictEntry2 = Entry()
dictEntry2.meanings = ["book"];
// This is the search term the user entered
String query = "tes";
Now I would like a way to query all Entrys in the DB that have "tes" as a substring of any of their meanings.
Thanks for the suggestion!
For now you will have to write your own filter code for this or remodel your data to use existing query conditions.
Side note: the current contains condition will only match if an element is equal to the search term. E.g. "there" will match ["hello", "there"], but "the" will not.
@greenrobot-team How can I write my own Filter Code? Here is state filters are only for java/kotlin.
@CaptainDario Dart has built-in helpers to filter iterables, e.g. where().
@greenrobot-team how likely is that this will be implemented any time soon?
Is it very difficult to do so? Because just using .getAll() and then .where() on the result is very slow.
No plans right now.
Maybe create a separate box with meanings that link back to an Entry, then your code can query that using a contains condition? Something like:
class Meaning {
@Index()
String meaning;
@Backlink('meanings')
final entries = ToMany<Entry>();
}
class Entry {
final meanings = ToMany<Meaning>();
}
Thank you for your help! Gonna give this a try.