Realm-java: RealmResults<SomeClass> and Observable.concat()

Created on 16 Jan 2017  路  4Comments  路  Source: realm/realm-java

I have trouble with concat two RealmResults, can i get result as RealmResults or only List?

Observable> asyncObservable1 = realm.where(SomeClass.class) .findAllSortedAsync("field") .asObservable();

Observable> asyncObservable1 = realm.where(SomeClass.class) .beginsWith("field", filterString).findAllSortedAsync("field") .asObservable();

Observable.concat(asyncObservable1, asyncObservable2).startWith(asyncObservable1). .filter(RealmResults::isLoaded)
.subscribe(this::filterObserver);

void filterObserver(RealmResults words) {
updateRealmResults(words);
}

I need filter Realm database filter by string with formatting:

Needle?
?Needle?
?Needle

T-Help

Most helpful comment

You cannot concatenate RealmResults but doing a Or of two queries is supported.

All 4 comments

    RealmResults<Cat> equalTo;
    RealmResults<Cat> beginsWith;

    @Override
    public void onViewRestored() {
        compositeSubscription = new CompositeSubscription();
        equalTo = realm.where(Cat.class).equalTo("field", filterString).findAllSorted("field");
        beginsWith = realm.where(Cat.class).beginsWith("field", filterString).findAllSorted("field");
        compositeSubscription.add(realm.asObservable()
                .switchMap(new Func1<Realm, Observable<Cat>>() {
                    @Override
                    public Observable<Cat> call(Realm realm) {
                        return Observable.concat(Observable.from(equalTo), Observable.from(beginsWith));
                    }
                })
                .toList()
                .subscribe(cats -> {
                    // update adapter with List<Cat>
                }));

Maybe someone smarter can make it work with the Async operators and filter too.

Can the like predicate (see #3752) be of any use here?

Yes, (like) predicate is best for my task, buy i used Realm version below 2.0

You cannot concatenate RealmResults but doing a Or of two queries is supported.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bryanspano picture bryanspano  路  3Comments

cmelchior picture cmelchior  路  3Comments

Merlin1993 picture Merlin1993  路  3Comments

David-Kuper picture David-Kuper  路  3Comments

mithrann picture mithrann  路  3Comments