objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.4k stars 302 forks source link

QueryFilter is not working when use findIds() ,but use find() is working #507

Closed andy37380 closed 6 years ago

andy37380 commented 6 years ago

Issue Basics

Reproducing the bug

Description

QueryFilter is not working when use findIds() ,but use find() is working

Code

@Entity
public class Note {
    @Id public long id;
    public String title; 
    public String context;
}

QueryBuilder<Note > queryBuilder = NoteBox.query();
queryBuilder = queryBuilder.filter(new QueryFilter<Note>() {
    @Override
    public boolean keep(Noteentity) {
        return entity.context.length() > 100;
    }
});

long[] ids = queryBuilder.build().findIds();
greenrobot-team commented 6 years ago

This is because a QueryFilter runs after the results are already returned from your BoxStore "on the Java side". Check out the Query.find() source code to see how it actually works. For findIds() the BoxStore only returns IDs to the Java side, so the query filter can not be used.

You may be able to solve your task by subscribing to the query and transforming its results to just return the note id. -ut

andy37380 commented 6 years ago

Thanks for reply.

greenrobot-team commented 6 years ago

Alright, closing then. Please re-open if your question was not answered. -ut

mecoFarid commented 2 years ago

@greenrobot-team Quick question. Is this documented somewhere? If not, adding documentation or maybe keeping the issue open would be more helpful. I have been looking at every side of the project for a couple of hours. I would suggest adding a bug tag instead of a feature

greenrobot-team commented 2 years ago

@mecoFarid What is documented? E.g. the findIds() method API documentation explicitly states that a query filter is not applied.