Hello,

As a matter of fact I just did exactly that.
I didn't modify directly LocalQuery class though, but added two subclasses of LocalQuery and LocalSession.

Seems to work pretty well.

Regards

Simon


Here is the code, if you are interested.

//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// Sub class of LocalQuery //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
package org.basex.api.client;

import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Logger;
import org.basex.core.Context;

public class MyLocalQuery extends LocalQuery {

    MyLocalQuery(final String query, final Context context, final OutputStream output) {
        super(query, context, output);
    }

    public int size() throws IOException {
        if (cache == null) {
            cache();
        }
        return cache.size();
    }
}


//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// END Sub class of LocalQuery //////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// Sub class of LocalSession ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
package org.basex.api.client;

import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.basex.core.Context;

public class MyLocalSession extends LocalSession {

    public MyLocalSession(Context context, OutputStream output) {
        super(context, output);
    }
    @Override
    public MyLocalQuery query(final String query) {
        return new MyLocalQuery(query, context(), out);
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// END Sub class of LocalSession ///////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


On Fri, Mar 13, 2015 at 2:01 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Ketill,

If you want, you can check out the Query and LocalQuery code and add a
function, which returns the value of cache.size(). If it works out for
you, we may add it to the offiicial API.

Hope this helps,
Christian


On Fri, Mar 13, 2015 at 12:04 PM, Ketill Fenne <ketill.fenne@gmail.com> wrote:
> Hi!
>
> I am using Query / LocalQuery to loop through the results from a query. For
> several reasons it would be nice to know the number of hits before/without
> looping through the results.
>
> Is this possible?
>
> Kind regards
> Ketill Fenne