Query / LocalQuery and number of hits

Friday, 13 March 2015 · 3 messages
KF
Ketill Fenne13 Mar 2015 12:04 #
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
CG
Christian Grün13 Mar 2015 14:01 #
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
Quoted text · Ketill Fenne · 11 lines
On Fri, Mar 13, 2015 at 12:04 PM, Ketill Fenne <ketill.fenne at 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
SC
Simon Chatelain13 Mar 2015 15:43 #
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
///////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
Quoted text · Christian Grün · 27 lines
On Fri, Mar 13, 2015 at 2:01 PM, Christian Grün <christian.gruen at 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 at 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 >

⚡Generated with XQuery