Example usage for org.apache.lucene.util Accountables toString

List of usage examples for org.apache.lucene.util Accountables toString

Introduction

In this page you can find the example usage for org.apache.lucene.util Accountables toString.

Prototype

public static String toString(Accountable a) 

Source Link

Document

Returns a String description of an Accountable and any nested resources.

Usage

From source file:IndexAndSearchOpenStreetMaps1D.java

License:Apache License

private static void queryIndex() throws IOException {
    Directory dir = FSDirectory.open(Paths.get("/l/tmp/1dkd" + (USE_NF ? "_nf" : "")));
    System.out.println("DIR: " + dir);
    IndexReader r = DirectoryReader.open(dir);
    System.out.println("maxDoc=" + r.maxDoc());

    IndexSearcher s = new IndexSearcher(r);

    //System.out.println("reader MB heap=" + (reader.ramBytesUsed()/1024/1024.));

    // London, UK:
    int STEPS = 5;
    double MIN_LAT = 51.0919106;
    double MAX_LAT = 51.6542719;
    double MIN_LON = -0.3867282;
    double MAX_LON = 0.8492337;
    byte[] scratch1 = new byte[4];
    byte[] scratch2 = new byte[4];
    for (int iter = 0; iter < 100; iter++) {
        long tStart = System.nanoTime();
        long totHits = 0;
        int queryCount = 0;
        for (int latStep = 0; latStep < STEPS; latStep++) {
            double lat = MIN_LAT + latStep * (MAX_LAT - MIN_LAT) / STEPS;
            for (int lonStep = 0; lonStep < STEPS; lonStep++) {
                double lon = MIN_LON + lonStep * (MAX_LON - MIN_LON) / STEPS;
                for (int latStepEnd = latStep + 1; latStepEnd <= STEPS; latStepEnd++) {
                    double latEnd = MIN_LAT + latStepEnd * (MAX_LAT - MIN_LAT) / STEPS;
                    for (int lonStepEnd = lonStep + 1; lonStepEnd <= STEPS; lonStepEnd++) {
                        double lonEnd = MIN_LON + lonStepEnd * (MAX_LON - MIN_LON) / STEPS;

                        Query q;/*from   w w  w .  j a v  a 2  s.  c o m*/
                        if (USE_NF) {
                            q = LegacyNumericRangeQuery.newIntRange("latnum", (int) (1000000. * lat),
                                    (int) (1000000. * latEnd), true, true);
                        } else {
                            q = IntPoint.newRangeQuery("lat", (int) (1000000. * lat),
                                    (int) (1000000. * latEnd));
                        }

                        TotalHitCountCollector c = new TotalHitCountCollector();
                        //long t0 = System.nanoTime();
                        s.search(q, c);

                        //System.out.println("\nITER: now query lat=" + lat + " latEnd=" + latEnd + " lon=" + lon + " lonEnd=" + lonEnd);
                        //Bits hits = reader.intersect(lat, latEnd, lon, lonEnd);
                        //System.out.println("  total hits: " + hitCount);
                        //totHits += ((FixedBitSet) hits).cardinality();
                        //System.out.println("  add tot " + c.getTotalHits());
                        totHits += c.getTotalHits();
                        queryCount++;
                    }
                }
            }
        }

        long tEnd = System.nanoTime();
        System.out.println("ITER: " + iter + " " + ((tEnd - tStart) / 1000000000.0) + " sec; totHits=" + totHits
                + "; " + queryCount + " queries");

        if (iter == 0) {
            long bytes = 0;
            for (LeafReaderContext ctx : r.leaves()) {
                CodecReader cr = (CodecReader) ctx.reader();
                System.out.println(Accountables.toString(cr));
                bytes += cr.ramBytesUsed();
            }
            System.out.println("READER MB: " + (bytes / 1024. / 1024.));
            System.out.println("RAM: " + Accountables.toString((Accountable) r.leaves().get(0).reader()));
        }
    }

    IOUtils.close(r, dir);
}

From source file:perf.SearchTaxis.java

License:Apache License

public static void main(String[] args) throws IOException, InterruptedException {
    Path indexPath = Paths.get(args[0]);

    String sparseOrNot = args[1];
    boolean sparse;
    if (sparseOrNot.equals("sparse")) {
        sparse = true;//from  w ww. j a  v a2 s . c  o  m
    } else if (sparseOrNot.equals("nonsparse")) {
        sparse = false;
    } else {
        throw new IllegalArgumentException("expected sparse or nonsparse but got: " + sparseOrNot);
    }

    Directory dir = FSDirectory.open(indexPath);

    IndexReader reader = DirectoryReader.open(dir);
    System.out.println("READER: " + reader);
    long bytes = 0;
    for (LeafReaderContext ctx : reader.leaves()) {
        CodecReader cr = (CodecReader) ctx.reader();
        System.out.println("\nREADER: " + cr);
        for (Accountable acc : cr.getChildResources()) {
            System.out.println("  " + Accountables.toString(acc));
        }
        bytes += cr.ramBytesUsed();
    }
    System.out.println("HEAP: " + bytes);

    IndexSearcher searcher = new IndexSearcher(reader);

    Random random = new Random(17);

    SearchThread[] threads = new SearchThread[2];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new SearchThread(i, sparse, searcher, 500, new Random(random.nextLong()));
        threads[i].start();
    }

    for (SearchThread thread : threads) {
        thread.join();
    }

    /*
    SearchThread[] threads = new SearchThread[] {new SearchThread(0, sparse, searcher, 1000, new Random(random.nextLong()))};
    threads[0].run();
    */

    for (SearchThread thread : threads) {
        for (String line : thread.results) {
            System.out.println(line);
        }
    }

    IOUtils.close(reader, dir);
}